ios 4 setBackgroundColor is not called by drawRect
This is probably a simple one bu开发者_高级运维t I really can't answer it.
I completed one of the demonstration apps shown in the CS193p class. It's basically a very simple view with a UISlider and a custom subview that does some drawing depending on the value of the slider. (It's a smiley face, quite cool!)
I decided to add a delegate protocol to the custom view, one that returns a UIColor object so that when the slider made the face happy it would also make the background of the view change from red to green.
That works fine, but the background starts out as white! As soon as I touch the slider, BOOM goes to RED and works fine... but it starts out as WHITE?! Why?!!
Without seeing your code, I would guess that the background color is being set in the nib file. If you aren't using interface builder, there is a chance that the default value for the background is white, but I am not sure about that.
I would check your nib file and see what the view's background color is set to. additionally, I would set the background color on the view in your viewDidLoad method to whatever you want it to start out as.
Feel free to post some of your code if I am way off base...
The background color is initially white because changing the backgroundcolor
does not change the color immediately. The color is changed the next time the view is redrawn, such as when you move the slider.
精彩评论