简体   繁体   English

UILabel 自动改变颜色

[英]UILabel automatically changes color

i'm facing a really strange problem: i have some UILabel in my view, which has a black background, so i set their text color to white in Interface Builder in order to see them, the problem is, when i run the app on the simulator or on my iphone with ios7 or iOS 6.1.3 i can update them without problems (for update i mean: myLabel.text = @"Something")我面临一个非常奇怪的问题:我的视图中有一些 UILabel,它有黑色背景,所以我在 Interface Builder 中将它们的文本颜色设置为白色以便看到它们,问题是,当我在模拟器或我的 iphone ios7 或 iOS 6.1.3 我可以毫无问题地更新它们(更新我的意思是:myLabel.text = @“Something”)

but when i run the app on my sister's iphone 3gs with iOS 6.0 at the moment i update them the font color turns black.但是当我用 iOS 6.0 在我姐姐的 iphone 3gs 上运行应用程序时,我更新它们时字体颜色变成黑色。 It seems that on her phone the label can't remember the color set on IB.好像她手机上的label不记得IB上设置的颜色。

Does anyone of you know why this happens?你们有人知道为什么会这样吗? Thanks谢谢

It sounds like you have set the label "type" to "Attributed" in Interface Builder. 听起来您已经在Interface Builder中将标签“类型”设置为“属性”。

If this is the case then it is not the label that holds the text colour. 如果是这种情况,则不是标签保留文字颜色。 It is the text itself. 它是文本本身。

If you replace the text with something else then the default text color of black will be used. 如果您用其他内容替换文本,则将使用默认的黑色文本颜色。

If you want to continue using Attributed text then you need to add a "foregroundColor" attribute to the text before setting it to the label. 如果要继续使用属性文本,则需要先在文本上添加“ foregroundColor”属性,然后再将其设置为标签。

The easier way round this is to change the label type to "Plain" in Interface Builder. 解决此问题的更简单方法是在Interface Builder中将标签类型更改为“ Plain”。

Of course, this depends on you having set it to Attributed. 当然,这取决于您已将其设置为Attributed。

我认为您不应在界面构建器中使用默认标签颜色,而应提供其他颜色(黑色等)。

I ran into a similar problem.我遇到了类似的问题。 Was stumping me completely, until I quit and relaunched the simulator.完全难倒我,直到我退出并重新启动模拟器。 It wasn't enough to just close the window or rebuild.仅仅关闭 window 或重建是不够的。 I had to cmd-q, then build and launch again.我不得不 cmd-q,然后再次构建和启动。 Magically fixed the issue.神奇地解决了这个问题。 Annoying.. but worked for me烦人..但对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM