ios 4 setBackgroundColor 不被drawRect调用
这可能是一个简单的问题,但我真的无法回答。
我完成了 CS193p 课程中展示的演示应用程序之一。它基本上是一个非常简单的视图,带有 UISlider 和自定义子视图,根据滑块的值进行一些绘制。 (这是一张笑脸,非常酷!)
我决定向自定义视图添加一个委托协议,该协议返回一个 UIColor 对象,这样当滑块使脸部高兴时,它也会使视图的背景从红色变为绿色的。
效果很好,但背景一开始是白色的!一旦我触摸滑块,BOOM 就会变成红色并且工作正常......但它一开始是白色的?!为什么?!!
This is probably a simple one but 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?!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有看到您的代码,我猜测背景颜色是在 nib 文件中设置的。如果您不使用界面生成器,则背景的默认值有可能是白色,但我不确定这一点。
我会检查您的 nib 文件并查看视图的背景颜色设置为什么。此外,我会将 viewDidLoad 方法中视图的背景颜色设置为您希望它开始的颜色。
如果我偏离基地,请随意发布一些你的代码......
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...
背景颜色最初为白色,因为更改
backgroundcolor
不会立即更改颜色。下次重新绘制视图时(例如移动滑块时),颜色会更改。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.