Delay when updating the background of a UIButton

1.2k Views Asked by At

I'm using setBackgroundImage:forState: to update the background of a UIButton. The background is updated but only after a few seconds. There is obviously some refresh cycle at work here but I can't find exactly what the problem is. I've tried to play with setNeedsRefresh and setNeedsDisplay without any result.

How can I change the UIButton background instantaneously ?

Thanks

1

There are 1 best solutions below

4
On BEST ANSWER

Strange delays like this are usually caused when you try and perform UIKit operations on a background thread (e.g. in a delegate callback). Try this:

dispatch_async(dispatch_get_main_queue(), ^{
    // set your button background here
});