简体   繁体   中英

How to check between play/pause button images

Lets say I have image1 as Play Icon.png and image2 as pause.png .

I want to do something like this, if the buttons image is image1 do this and if buttons image is image2 do that.

[playpauseButton setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateNormal];

[playpauseButton setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateSelected];

how do i find out wheter its Play Icon.png or pause.png .

Thanks

You can't easily determine what image is inside your " UIButton " but since you're setting that image by state, just check the state property of the button.

Then you'll know which image you are using.

It can be as easy as:

if( playpauseButton.state == UIControlStateSelected )
    NSLog( @"Here I am using pause.png");

or, if you're doing this inside an action:

- (IBAction) buttonPushed: (id) sender
{
    UIButton * theButton = (UIButton *) sender;
    if(theButton)
    {
        if( theButton.state == UIControlStateSelected )
            NSLog( @"Here I am using pause.png");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM