Issue in adding image to the UIButton. - iphone

I got an another problem in my application and I am wasting so much of time on that.
Does pls anyone can help with this problem.
Actually I had an Event and I should give rating for that event for that I wrote the code as:
In CellForRowAtIndexPath......I had the code as:
(UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MasterViewIdentifier"];
//UITableViewCell *cell = nil;
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:#"MasterViewIdentifier"] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIView* elementView = [[UIView alloc] initWithFrame:CGRectMake(20,170,320,280)];
elementView.tag = 0;
elementView.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:elementView];
[elementView release];
}
UIView* elementView = [cell.contentView viewWithTag:0];
elementView.backgroundColor=[UIColor clearColor];
for(UIView* subView in elementView.subviews)
{
[subView removeFromSuperview];
}
if(indexPath.section == 8)
{
UIImage *whiteImg = [UIImage imageNamed:#"white_star.png"] ;
UIImage *yellowImg = [UIImage imageNamed:#"yellow_Star.png"] ;
UIButton *button1 = [[UIButton alloc]initWithFrame:CGRectMake(159, 15, 25, 20)];
[button1 addTarget:self action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
button1.tag = 1;
UIButton *button2 = [[UIButton alloc]initWithFrame:CGRectMake(185, 15, 25, 20)];
[button2 addTarget:self action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
button2.tag = 2;
UIButton *button3 = [[UIButton alloc]initWithFrame:CGRectMake(211, 15, 25, 20)];
[button3 addTarget:self action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
button3.tag = 3;
UIButton *button4 = [[UIButton alloc]initWithFrame:CGRectMake(237, 15, 25, 20)];
[button4 addTarget:self action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
button4.tag = 4;
UIButton *button5 = [[UIButton alloc]initWithFrame:CGRectMake(263, 15, 25, 20)];
[button5 addTarget:self action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
button5.tag = 5;
if(event.eventRatings == 1)
{
[button1 setBackgroundImage:yellowImg forState:UIControlStateNormal];
[button2 setBackgroundImage:whiteImg forState:UIControlStateNormal];
[button3 setBackgroundImage:whiteImg forState:UIControlStateNormal];
[button4 setBackgroundImage:whiteImg forState:UIControlStateNormal];
[button5 setBackgroundImage:whiteImg forState:UIControlStateNormal];
}
else if(event.eventRatings == 2)
{
[button1 setBackgroundImage:yellowImg forState:UIControlStateNormal];
[button2 setBackgroundImage:yellowImg forState:UIControlStateNormal];
[button3 setBackgroundImage:whiteImg forState:UIControlStateNormal];
[button4 setBackgroundImage:whiteImg forState:UIControlStateNormal];
[button5 setBackgroundImage:whiteImg forState:UIControlStateNormal];
}
else if(event.eventRatings == 3)
{
[button1 setBackgroundImage:yellowImg forState:UIControlStateNormal];
[button2 setBackgroundImage:yellowImg forState:UIControlStateNormal];
[button3 setBackgroundImage:yellowImg forState:UIControlStateNormal];
[button4 setBackgroundImage:whiteImg forState:UIControlStateNormal];
[button5 setBackgroundImage:whiteImg forState:UIControlStateNormal];
}
else if(event.eventRatings == 4)
{
[button1 setBackgroundImage:yellowImg forState:UIControlStateNormal];
[button2 setBackgroundImage:yellowImg forState:UIControlStateNormal];
[button3 setBackgroundImage:yellowImg forState:UIControlStateNormal];
[button4 setBackgroundImage:yellowImg forState:UIControlStateNormal];
[button5 setBackgroundImage:whiteImg forState:UIControlStateNormal];
}
else if(event.eventRatings == 5)
{
[button1 setBackgroundImage:yellowImg forState:UIControlStateNormal];
[button2 setBackgroundImage:yellowImg forState:UIControlStateNormal];
[button3 setBackgroundImage:yellowImg forState:UIControlStateNormal];
[button4 setBackgroundImage:yellowImg forState:UIControlStateNormal];
[button5 setBackgroundImage:yellowImg forState:UIControlStateNormal];
}
else
{
[button1 setBackgroundImage:whiteImg forState:UIControlStateNormal];
[button2 setBackgroundImage:whiteImg forState:UIControlStateNormal];
[button3 setBackgroundImage:whiteImg forState:UIControlStateNormal];
[button4 setBackgroundImage:whiteImg forState:UIControlStateNormal];
[button5 setBackgroundImage:whiteImg forState:UIControlStateNormal];
}
[elementView addSubview:button1];
[button1 release];
[elementView addSubview:button2];
[button2 release];
[elementView addSubview:button3];
[button3 release];
[elementView addSubview:button4];
[button4 release];
[elementView addSubview:button5];
[button5 release];
if(isRightButton == YES)
{
button1.enabled = NO;
button2.enabled = NO;
button3.enabled = NO;
button4.enabled = NO;
button5.enabled = NO;
}
else if(isRightButton == NO)
{
button1.enabled = YES;
button2.enabled = YES;
button3.enabled = YES;
button4.enabled = YES;
button5.enabled = YES;
}
[elementView addSubview:ratingsTitleLabel];
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
And the action of the button is written as:
-(void)buttonAction:(id)sender
{
rating = [sender tag];
printf("\n Ratig Value inside Button Action~~~~~~~~~~~~~~~~%d",rating);
event.eventRatings = rating;
[tableView reloadData];
}
When I build the application in simlator of 3.1.2 O.S its working fine by displaying the star images.
My porblem is when I build it in 3.1.2 O.S Device the images are not displaying.I checked the code for casesensitivity in file name and its gud but Im not gettig the images to display.
Guys help me to solve this.
Thank you,
Monish Kumar.

Try this:
- delete your app from iPhone
- clear all tagets from build menu
- copy your images in another dir
- delete images from project (when delete click " Also Move to Trash")
- add your images again
- build and go
Hope it works.

Related

calling the ibaction method programmatically is not changing the background of the button?

I had an application in which I am adding some dynamic number of buttons to a scrollview. I had set a normal background and selected background for the UIButton. For some reasons I need to call the UIButton sender method programmatically by:
[self buttontapped:nil];
as this but it is not changing the background of the button by using the code:
button.selected = YES;
I had set the background like this initially of the button:
btn = [UIButton buttonWithType:UIButtonTypeCustom];
int j = i+1;
btn.frame = CGRectMake((j-1)*77, 0, 77, 44);
[btn setBackgroundImage:[UIImage imageNamed:#"bar.png"] forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:#"bar_hvr.png"] forState:UIControlStateSelected];
btn.selected = NO;
btn.backgroundColor = [UIColor clearColor];
btn.titleLabel.font = [UIFont fontWithName:#"Helvetica-Bold" size:14];
btn.titleLabel.textColor = [UIColor whiteColor];
[btn setTitle:head forState:UIControlStateNormal];
btn.tag = i;
[tabBarS addSubview:btn];
-(void)buttonTapped:(id)sender {
if(sender==nil)
{
btn.tag=0;
}
for(int i=0;i<[sarray count];i++)
{
btn.selected=NO;
}
btn = (UIButton *)sender;
NSLog(#"Tab bar %d is clicked",btn.tag);
[self tabCall:btn.tag];
btn.selected = YES;
}
But everything except change of background only working. Where am I going wrong?
i done with bellow method call your UIButton method like:-
btn= [UIButton buttonWithType:UIButtonTypeCustom];
int j=i+1;
btn.frame = CGRectMake((j-1)*77, 0, 77, 44);
[btn setBackgroundImage:[UIImage imageNamed:#"bar.png"] forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:#"bar_hvr.png"] forState:UIControlStateSelected];
btn.selected=NO;
[btn addTarget:self action:#selector(yourButtonAction:) forControlEvents:UIControlEventTouchUpInside];
btn.backgroundColor = [UIColor clearColor];
btn.titleLabel.font = [UIFont fontWithName:#"Helvetica-Bold" size:14];
btn.titleLabel.textColor = [UIColor whiteColor];
btn.tag = i;
[tabBarS addSubview:btn];
and it's Action Method should like with sender
-(IBAction)yourButtonAction:(id)sender
{
UIButton *btn = (UIButton*)sender;
if (![btn isSelected])
{
[btn setImage:[UIImage imageNamed:#"selected_fb_btn.png"] forState:UIControlStateNormal];
[btn setSelected:YES];
[self login];
}
else{
[btn setImage:[UIImage imageNamed:#"facebook.png"] forState:UIControlStateNormal];
[btn setSelected:NO];
}
}
EDIT
You can call button action event programeticuly using bellow trik:-
[btn sendActionsForControlEvents:UIControlEventTouchUpInside];
write this bellow line first and also change the method type from void to IBAction...
btn = (UIButton *)sender;
like bellow...
-(IBAction)buttonTapped:(id)sender {
btn = (UIButton *)sender;
if(sender==nil)
{
btn.tag=0;
}
for(int i=0;i<[sarray count];i++)
{
[btn setSelected:NO];
}
NSLog(#"Tab bar %d is clicked",btn.tag);
[self tabCall:btn.tag];
[btn setSelected:YES];
}
You need to set image property rather than backgroundImage property of UIButton.
Use default Image property and selected property.
[btn setSelected:TRUE];
is the log that you are printing, prints the button.tag correctly?
NSLog(#"Tab bar %d is clicked",btn.tag);
In your button action
btn.selected=YES;
in last line makes the button in selected state always
also get the correct instance as
btn=(UIButton *)sender;

iPhone Button Selected State

I am created two buttons that are right next to each other to mimic a segmented control. I am doing this to customize the appearance beyond what the UIKit allows. I decided to use the selected property to keep a button pressed. I have two images that one for each state normal and selected.
The problem is that when I select a button, the button highlights and turns dark, because of the hightlight state. I decided to use the selected image for the highlight state too, but it flashes, any ideas or suggestions.
- (void)leftSegmentPressed:(id)sender
{
if ([sender isSelected]) {
[sender setSelected:NO];
}
else {
[sender setSelected:YES];
}
}
For the "selected" button, disable it and manually switch the image for the state.
- (void) viewDidLoad
{
[rightSegmentButton setImage:[UIImage imageNamed:#"unselected.png"] forState:UIControlStateNormal];
[rightSegmentButton setImage:[UIImage imageNamed:#"selected.png"] forState:UIControlStateDisabled];
[leftSegmentButton setImage:[UIImage imageNamed:#"unselected.png"] forState:UIControlStateNormal];
[leftSegmentButton setImage:[UIImage imageNamed:#"selected.png"] forState:UIControlStateDisabled];
}
- (void)leftSegmentPressed:(id)sender
{
sender.enabled = NO;
rightSegmentButton.enabled = YES;
}
- (void)rightSegmentPressed:(id)sender
{
sender.enabled = NO;
leftSegmentButton.enabled = YES;
}
Check whether the image you given is in your Bundle or check image name you given is in lower case or not. Then write like
[button1 setImage:[UIImage imageNamed:#"normal1.png"] forState:UIControlStateNormal];
[button1 setImage:[UIImage imageNamed:#"selected1.png"] forState:UIControlStateSelected];
[button2 setImage:[UIImage imageNamed:#"normal2.png"] forState:UIControlStateNormal];
[button2 setImage:[UIImage imageNamed:#"selected2.png"] forState:UIControlStateSelected];
button1.tag = 1;
button2.tag = 2;
[button1 addTarget:self action:#selector(buttonSelected:) forControlEvents:UIControlEventTouchUpInside]
[button2 addTarget:self action:#selector(buttonSelected:) forControlEvents:UIControlEventTouchUpInside]
in your button event method
-(void)buttonSelected:(id)sender {
if([sender tag] == 1) {
button1.selected = YES;
button2.selected = NO;
} else {
button1.selected = NO;
button2.selected = YES;
}
}
[button setAdjustsImageWhenHighlighted:NO];
This will prevent the flicker.
UIButton *yourButton1 = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
yourButton1.frame = CGRectMake(110.0, 360.0, 100.0, 30.0);
[yourButton1 setTitle:#"Left" forState:UIControlStateNormal];
yourButton.backgroundColor = [UIColor clearColor];
yourButton1.tag = 1;
[yourButton1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];
UIImage *buttonImageNormal = [UIImage imageNamed:#"yourNormalImage.png"];// set normal image
UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[yourButton1 setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];
UIImage *buttonImagePressed = [UIImage imageNamed:#"yourSelectedImage.png"];// set selected image
UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[yourButton1 setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted];
[yourButton1 addTarget:self action:#selector(leftSegmentPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:yourButton1];
do same for another second button.
and in action method set bellow code..
- (void)leftSegmentPressed:(id)sender
{
UIButton *btnTemp = (UIBUtton *)sender;
if (btnTemp.tag == 1) {
[yourButton1 setSelected:YES];
[yourButton2 setSelected:NO];
}
else {
[yourButton1 setSelected:NO];
[yourButton2 setSelected:YES];
}
}

Dynamic UIButton controlls and actions in iphone?

i am creating an application which includes dynamic pages. actually, i created some dynamic questions and UIButtons (custom checkBox) by checking the responses from the server.
my code is here,
NSString *response=[ResponseFromServer ObjectAtIndex:0];
if ([comSt compare: #"CheckBoxList"]==NSOrderedSame)
{
int count=[ResponseFromServer count];
for(int i=0;i<count;i++)
{
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.tag=i;
[button setFrame:CGRectMake(0.0f, 0.0f, 37, 37)];
[button setCenter:CGPointMake(116.0,p1)];
[button setImage:[UIImage imageNamed:#"uncheck.png"] forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor whiteColor]];
[button addTarget:self action:#selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.scrollView addSubview:button];
p1=p1+30;
}
-(void)checkButtonTapped:(id)sender
{
int tagVal = [(UIButton*)sender tag];
if (tagVal==0) {
NSLog(#"tag = 0");
[button setSelected:YES];
[button setImage:[UIImage imageNamed:#"check.png" forState:UIControlStateSelected]; //not working, button image is not changing
}
assume i have created 5 dynamic buttons with different tag. i set the image for all those button to uncheck.png first. it works.
but when i clicked a specific button and need to change that button image to checked.png, its not working on the button action.
i need to change it like checkBox control, how will i access the control of a dynamically created button from a group of buttons?
i think u can understand my requirement, thanks in advance..
While adding dynamic button set [button setSelected:NO];
Replace method and Add one method given below
-(void)checkButtonTapped:(id)sender
{
UIButton *curButton = (UIButton*)sender
if (curButton.tag==0)
{
[self buttonAction:curButton];
}
if (curButton.tag==1)
{
[self buttonAction:curButton];
}
// continues
}
-(void)buttonAction:(UIButton *)curButton
{
if(![curButton isSelected])
{
[curButton setSelected:YES];
[curButton setImage:[UIImage imageNamed:#"check.png" forState:UIControlStateSelected]; //not working, button image is not changing
} else {
[curButton setSelected:NO];
[curButton setImage:[UIImage imageNamed:#"uncheck.png"] forState:UIControlStateNormal];
}
}
In your code you need to change like this
Try this code
if ([comSt compare: #"CheckBoxList"]==NSOrderedSame)
{
int count=[ResponseFromServer count];
for(int i=0;i<count;i++)
{
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.tag=0;
[button setFrame:CGRectMake(0.0f, 0.0f, 37, 37)];
[button setCenter:CGPointMake(116.0,p1)];
[button setImage:[UIImage imageNamed:#"uncheck.png"] forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor whiteColor]];
[button addTarget:self action:#selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.scrollView addSubview:button];
p1=p1+30;
}
}
-(void)checkButtonTapped:(id)sender
{
int tagVal = [(UIButton*)sender tag];
if (tagVal==0) {
NSLog(#"tag = 0");
[button setSelected:YES];
[button setImage:[UIImage imageNamed:#"check.png" forState:UIControlStateSelected];
[button setTag:100];
}
else
{
[button setSelected:YES];
[button setImage:[UIImage imageNamed:#"uncheck.png" forState:UIControlStateSelected];
[button setTag:0];
}
}

Changing image on UIButton when user presses that button removing previous image

I want to change an image on my UIButton when a user presses on it. The image has transparency effects (it is a .png that shows only an edge). The problem is that when the button is tapped, all works fine (other functions connected to it), but the app overwrites the 2 different images one over the second! When the button is pressed I want to show the second image, and remove the first (that becomes unnecessary). PS: I don't want to use array of images. Here the code for the button
UIButton *overlayButton = [UIButton buttonWithType:UIButtonTypeCustom];
[overlayButton setImage:[UIImage imageNamed:#"image1.png"] forState:UIControlStateNormal];
[overlayButton setFrame:CGRectMake(20, 382, 120, 60)];
[overlayButton addTarget:self action:#selector(scanButtonPressed) forControlEvents:UIControlEventTouchUpInside]; //just graphics
[overlayButton addTarget:self action:#selector(buttonshapeClicked:) forControlEvents:UIControlEventTouchUpInside]; //just to set a variable i++ for my cycle
[overlayButton addTarget:self action:#selector(changeshape:) forControlEvents:UIControlEventTouchUpInside]; //function that changes another shape
[[self view] addSubview:overlayButton];
my simple cycle
- (void)buttonshapeClicked:(id)sender{
shape++;
if (shape == 4) {
shape = 1;
}}
here the main function that allows to change a primary shape on the screen
-(void) changeshape:(id)sender {
if (shape==1 && people==2) {
//bottone forma
UIButton *overlayButton = [UIButton buttonWithType:UIButtonTypeCustom];
[overlayButton setImage:[UIImage imageNamed:#"passaquadrato.png"] forState:UIControlStateNormal];
[overlayButton setFrame:CGRectMake(20, 382, 120, 60)];
[overlayButton addTarget:self action:#selector(scanButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[overlayButton addTarget:self action:#selector(buttonshapeClicked:) forControlEvents:UIControlEventTouchUpInside];
[overlayButton addTarget:self action:#selector(changeshape:) forControlEvents:UIControlEventTouchUpInside];
[[self view] addSubview:overlayButton];
//bottone people
UIButton *overlayButtonp = [UIButton buttonWithType:UIButtonTypeCustom];
[overlayButtonp setImage:[UIImage imageNamed:#"passatre.png"] forState:UIControlStateNormal];
[overlayButtonp setFrame:CGRectMake(180, 382, 120, 60)];
[overlayButtonp addTarget:self action:#selector(scanButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[[self view] addSubview:overlayButtonp];
UIImageView *overlayImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"circle2.png"]];
[overlayImageView setFrame:CGRectMake(20, 88, 280, 280)];
[[self view] addSubview:overlayImageView];
}
else if (shape==2 && people==2) {
//bottone forma
UIButton *overlayButton = [UIButton buttonWithType:UIButtonTypeCustom];
[overlayButton setImage:[UIImage imageNamed:#"passarettangolo.png"] forState:UIControlStateNormal];
[overlayButton setFrame:CGRectMake(20, 382, 120, 60)];
[overlayButton addTarget:self action:#selector(scanButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[overlayButton addTarget:self action:#selector(buttonshapeClicked:) forControlEvents:UIControlEventTouchUpInside];
[overlayButton addTarget:self action:#selector(changeshape:) forControlEvents:UIControlEventTouchUpInside];
[[self view] addSubview:overlayButton];
//bottone people
UIButton *overlayButtonp = [UIButton buttonWithType:UIButtonTypeCustom];
[overlayButtonp setImage:[UIImage imageNamed:#"passatre.png"] forState:UIControlStateNormal];
[overlayButtonp setFrame:CGRectMake(180, 382, 120, 60)];
[overlayButtonp addTarget:self action:#selector(scanButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[[self view] addSubview:overlayButtonp];
UIImageView *overlayImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"square2.png"]];
[overlayImageView setFrame:CGRectMake(20, 88, 280, 280)];
[[self view] addSubview:overlayImageView];
}}
Try like this:
UIButton *overlayButton = [UIButton buttonWithType:UIButtonTypeCustom];
[overlayButton setImage:[UIImage imageNamed:#"image1.png"] forState:UIControlStateNormal];
[overlayButton setFrame:CGRectMake(20, 382, 120, 60)];
[overlayButton addTarget:self action:#selector(setRightActionToButton:) forControlEvents:UIControlEventTouchUpInside];
[[self view] addSubview:overlayButton];
-(void)setRightActionToButton:(id)sender {
UIButton *button = (UIButton *)sender;
if (shape==1 && people==2) {
[button setImage:[UIImage imageNamed:#"image2.png"] forState:UIControlStateNormal];
[self scanButtonPressed:button]
}
else if (shape==2 && people==2) {
[button setImage:[UIImage imageNamed:#"image3.png"] forState:UIControlStateNormal];
[self buttonshapeClicked:button]
}
else if (shape==3 && people==2) {
[button setImage:[UIImage imageNamed:#"image4.png"] forState:UIControlStateNormal];
[self changeshape:button];
}
}

How to use lazy loading in UIButton image?

I use this logic for creating button in scroll view.
`int m=0;
int j = [imageData count]/3;
int s = [imageData count]%3;
if(s==1 || s==2)
{
j=j+1;
}
scrollView.contentSize = CGSizeMake(320,j*155);
int i,k,x=0,y=0;
for(i=0;i<j;i++)
{
if(s==0){
for(k=0;k<3;k++)
{
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(13+x,10+y, 91,135)];
int p;
NSLog(#"%i",p++);
[button setTag:m];
[button setBackgroundColor:[UIColor whiteColor]];
NSData *imagesubCategoryData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:[imageData objectAtIndex:m]]];
[button setImage:[UIImage imageWithData:imagesubCategoryData] forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:button];
x=x+101;
m++;
}
}
else if(s==1)
{
for(k=0;k<3;k++)
{
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(13+x,10+y, 91,135)];
[button setTitle:#"Button" forState:UIControlStateNormal];
int p;
NSLog(#"%i",p++);
[button setTag:m];
[button setBackgroundColor:[UIColor whiteColor]];
NSData *imagesubCategoryData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:[imageData objectAtIndex:m]]];
[button setImage:[UIImage imageWithData:imagesubCategoryData] forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:button];
x=x+101;
if(i==j-1 && k==0)
{
break;
}
m++;
}
}
else if(s==2)
{
for(k=0;k<3;k++)
{
button = [UIButton buttonWithType:UIButtonTypeCustom];;
[button setFrame:CGRectMake(13+x,10+y, 91,135)];
[button setTitle:#"Button" forState:UIControlStateNormal];
int p;
NSLog(#"%i",p++);
[button setTag:m];
[button setBackgroundColor:[UIColor whiteColor]];
NSData *imagesubCategoryData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:[imageData objectAtIndex:m]]];
[button setImage:[UIImage imageWithData:imagesubCategoryData] forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:button];
x=x+101;
if(i==j-1 && k==1)
{
break;
}
m++;
}
}
x=0;
y=y+145;
}
`
you can find Democode on lazy load at here
Hope from this one u can got logic for Lazy loading...