Tuesday, March 15, 2011

How to show button enabled OR How to change button image when button clicked on the basis of Tag value.

This is very useful code to access any view's object in code on the basis of it's tag value. 
The code I use here to update the image of weather button in any function(e.g. viewDidLoad) :
 button=(UIButton *)[self.view viewWithTag:1];
button.selected = YES;
button.highlighted = YES;
BImage = [UIImage imageNamed:@"image.jpg"];
[button setImage:BImage forState:UIControlStateNormal];

Explanation:  

button=(UIButton *)[self.view viewWithTag:1];
Here, we are typecasting any view object with tag value 1 to UIButton type. The tag value will be set in IB(you can also do programmatically).

1 comment:

  1. Nice post with great details. I really appreciate your idea. Thanks for sharing.

    -------------------------------------------------------------------------------------------------
    iPhone 5 App Development & iPad Application Developer

    ReplyDelete