开发者

UIButton changes his background color for a while from white to gray

开发者 https://www.devze.com 2023-04-08 21:04 出处:网络
I have an UIButton with an image made with a white background and a figure in the center. On click this image must be changed with another. The problem born when i click on button his background becom

I have an UIButton with an image made with a white background and a figure in the center. On click this image must be changed with another. The problem born when i click on button his background become light gray while it change the image. It happens only the first time i click. I made this app to play sound when i click on button and change the image. When the sound finishes to play, the image return to the original.

This is the viewDidLoad

- (void)viewDidLoad
{
    [super viewDidLoad];
    imageOpen = [UIImage imageNamed:@"aperto.jpg"];
    imageClosed = [UIImage imageNamed:@"chiuso.jpg"];
    CGRect rect = CGRectMake(([UIScreen mainScreen].bounds.size.width - imageOpen.size.width)/2,([UIScreen mainScreen].bounds.size.height - imageOpen.size.height)/2, imageOpen.size.width, imageOpen.size.height);
    [bottone setFrame:rect];
    [bottone setImage: imageOpen forState: UIControlStateNormal];  
    ...
}

This is the function called when the button is clicked:

- (IBAction)launchDialog
{  
    [bottone setImage:imageClosed forState: UIControlStateNormal];
    if(self.player.playing==TRUE){
        [self.player stop]; 
    }
    self.player.currentTime = 0;
    [self.player play];
}

And this is the method called when the sound finishes to play:

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player succ开发者_如何学JAVAessfully:(BOOL)flag {
    [bottone setImage: imageOpen forState: UIControlStateNormal];
}

What is the problem? what can i do?


You need to set all the states of your button. Did you do that where you indicate that you are configuring the button with //...?

These are the four states that you have to set:

UIControlStateNormal               
UIControlStateHighlighted          
UIControlStateDisabled             
UIControlStateSelected    
0

精彩评论

暂无评论...
验证码 换一张
取 消