Thursday, May 30, 2013

UIButton currentImage example in Objective C (iOS).

UIButton currentImage

The current image displayed on the button. (read-only)

@property(nonatomic, readonly, retain) UIImage *currentImage

Discussion of [UIButton currentImage]
This value can be nil.

UIButton currentImage example.
self.currentImage = @"Penguin.png";
[m1 setImage:[UIImage imageNamed: currentImage] forState:UIControlStateNormal];
Then when you need to check the value:

if ([@"Penguin.png" isEqual:self.currentImage]) {
    do something;

Example of [UIButton currentImage].
UIButton *tmpYes = (UIButton *)sender;
[self ClearAllButtons:tmpYes.tag:@"YES"];
UIImage* selectedImg=[UIImage imageNamed:@"checkboxtick.png"];
if (tmpYes.currentImage == selectedImg )

    [tmpYes setImage:[UIImage imageNamed:@"checkboxtick.png"] forState:UIControlStateNormal];
NSLog(@"Button tag is %d",tmpYes.tag);

UIButton currentImage example.
if (SquareToCheck.currentImage == [UIImage imageNamed:@"Image1.PNG"]) {
MyImageAsString = @"Image1.PNG";

End of UIButton currentImage example article.