1

I'm trying change background color of UIView. here is my code:

UIView *myView = [self.view viewWithTag:21];
[self.view bringSubviewToFront:myView];
myView.backgroundColor = [UIColor yellowColor];

I verified :

if ([myView.backgroundColor isEqual:[UIColor yellowColor]])
    {
        NSLog(@"my view is yellow!");
    }

but in the screen of the iPhone never change colors. I tried the same code in different project and it works just fine. Any of you knows what can be wrong?

user2924482
  • 8,380
  • 23
  • 89
  • 173

2 Answers2

0

Well you're doing something that comes off a little unclear from that code snippet.

That code is absolutely correct for what you're trying to do, but I'm assuming you're having that problem due to code elsewhere in your program.

For example: if you hide the view at some point, you won't get the color change. If the view is ever "locked" in some manner, you would have a problem. Or if this operation is on a background thread that could also cause the hang up.

So I would look at the rest of the code and see if something else is impeding it.

Andrew
  • 3,874
  • 5
  • 39
  • 67
  • I understand it just weird. I even tried to reset the location of the view "myView.frame = CGRectMake(0, 0,280,323);" and doesn't work. – user2924482 Sep 04 '14 at 21:42
  • Something fishy is going on. But this is going to be hard to debug without all of your code – Andrew Sep 05 '14 at 01:39
0

Make sure you're doing UI changes in the main thread, not in a completion handler, or any other background task.

Owen Hartnett
  • 5,925
  • 2
  • 19
  • 35