Is it possible to change the button image in viewdidload/viewwillappear function. If possible then how the particula开发者_Go百科r button(if I have 2 buttons) will identify in these function.
This is the code I use to update the image of weather button in my viewDidLoad:
UIImage *img = [[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:iconURL]]] retain];
if (img != nil)
{
[weatherButton setImage:img forState:normal];
img = nil;
}
I am getting the image from a URL. Hope this helps.
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor = [UIColor clearColor];
button.frame = CGRectMake(275, 8, 40.0, 40.0);
[button setBackgroundImage:[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"button_home.png"]] forState:UIControlStateNormal];
[button addTarget:self action:@selector(goHome) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
[self.view bringSubviewToFront:button];
Here I have created the button programmatically!
Yes, u can use this
[button setImage:image forState:state];
精彩评论