Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get image name from an UIButton on iPhone sdk?

I'm trying to get the name of the background image from a custom button.

I call this method when I click over the UIButton:

-(void)getButtonImageName:(id)sender{       
    UIButton *resultButton = (UIButton *)sender;
    NSLog(@" The button's image is %@.", resultButton.currentImage);
}

I can get the title and other properties from the button but not the background image name.

Anyone know how to do that? Thanks!

like image 705
karse23 Avatar asked Feb 14 '11 09:02

karse23


1 Answers

This is the simplest approach to get the current image of a custom button

-(void)yesButtonButtonCliked:(id)sender
{
    UIButton *tmpYes = (UIButton *)sender;
    [self ClearAllButtons:tmpYes.tag:@"YES"];
    UIImage* selectedImg=[UIImage imageNamed:@"checkboxtick.png"];
    if (tmpYes.currentImage == selectedImg ) 
    {

    }
    else
    {
        [tmpYes setImage:[UIImage imageNamed:@"checkboxtick.png"] forState:UIControlStateNormal];
    }
    NSLog(@"Button tag is %d",tmpYes.tag);
}
like image 191
Shantanu Avatar answered Oct 24 '22 01:10

Shantanu