开发者

Adding array of images to UIbuttons

开发者 https://www.devze.com 2023-03-12 22:26 出处:网络
I have some uiButtons in my table view and i want to load them with images which i get from an array. But i am not able to add images to the button usin开发者_开发问答g the array and it is crashing my

I have some uiButtons in my table view and i want to load them with images which i get from an array. But i am not able to add images to the button usin开发者_开发问答g the array and it is crashing my entire app. Can anyone provide me the solution of how to add images to buttons in table view using Array of Images.Any help will be appreciated.

This method is called from a loop where i am passing a button as the parameter

-(void)setImage1:(UIButton *)button
UIButton *newButton=[[UIButton alloc]init]; 
newButton=button; 

[newButton setImage:[NSString stringWithFormat:@"%d.png", j] forState:UIControlStateNormal]; j++; } 

Thanks, Christy


//Create an image
UIImage *image= [UIImage imageWithContentsOfFile:@"image.jpg"];

// Set image for the button
[button setBackgroundImage:image forState:UIControlStateNormal];

Show us some code at least for more help.

You should not create the button within that method. Create it in ViewDidLoad, or even better, in Interface builder. If you create a button programatically you will have to also make sure you enable user interaction, and then set its frame and add it to the view.

0

精彩评论

暂无评论...
验证码 换一张
取 消