Change the background image of a UIButton more than once per second

I am currently working with the iPhone SDK.

I have an NSTimer that changes the background image of a UIButton. Once this is completed, it will again launch the same action (reset NSTimer) for a certain number of times.

My problem is if my NSTimer is configured to run more than once per second. (0.75, say) The background image will not change.

I use NSLog to verify that the event is firing. But the button image will remain in its original state.

Is there a way to change the background image more than once per second?

This is my timer:

[NSTimer scheduledTimerWithTimeInterval: tmpLvlSpeed target: self selector: @selector(simPressRed:) userInfo: nil repeats: NO]; 

And the code to change the image:

 [btnRed setImage:[UIImage imageNamed:@"btn_red.png"] forState:UIControlStateNormal]; 

if tmpLvlSpeed ​​is less than 1.0, the button image will never change. Despite the fact that the simPressRed function still works.

Any clues? Is it possible to change the update cycle?

+4
source share
2 answers

Have you tried using setNeedsDisplay ?

 [button setNeedsDisplay]; 
+3
source

how many images do you have? From what you gave us, you have only one image, so the image will not change. Please post the code you have so that we can help you.

0
source

Source: https://habr.com/ru/post/1305730/


All Articles