我怎样才能使新的 UILabel 的默认颜色为黑色(而不是透明)
我想尽可能多地使用IB。因此我想将 UILabel 从 Library 调色板拖到 UIView 中。当我这样做时,UILabel 设置为白色(默认)。我希望默认颜色为黑色。我知道我可以通过编程来做到这一点,但我试图避免这种情况。
问题: 我创建了一个 UIScrollView。我设置了尺寸,然后尝试添加 UILabels。
然而,标签都是白色文本(很烦人,因为我必须更改每个标签的颜色属性)。
有没有办法使所有标签(从IB拖动到视图的新标签)具有默认的黑色文本颜色?
I want to use IB as much as I can. Therefore I want to drag UILabel from the Library palette to the UIView. When I do this, the UILabel is set to white (default). I want the default color to be Black. I know I can do this programatically but I am trying to avoid that.
The problem:
I created a UIScrollView. I set up the dimensions and then I am trying to add UILabels.
However the labels are all white text (annoying because I have to change the color property per label).
Is there a way to make all labels (new ones that are dragged from IB to the view) have a default text color of black?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,如果更改就像更改背景颜色一样微不足道,并且您想要更改默认颜色,则必须有数百个(或至少数十个)标签,这告诉我真正的问题在其他地方。
但是,如果您真的想要这样做,我可以想到几种方法:
子类 UILabel 并覆盖 initWithCoder 或在您的子类中更改颜色。然后更改标签的类以指向您的子类,这并不比更改颜色更容易,而且您甚至不会在 IB 中看到结果。
如果这是任何其他 UIView 子类,则可以在协议中重写 drawRect 。要使其适用于 UILabel,您可能还必须进行文本绘制,但您仍然不会在 IB 中看到结果。只是列出您的选项。
如果你真的想在IB中看到结果,你可以疯狂地创建一个IB插件,这可能是用大锤打死苍蝇的定义:http://cocoawithlove.com/2009/07/custom-views-in-interface-builder-using.html
最后,你可以等待 iOS 5 和 UIAppearance 了。查看“iOS 5 有哪些新功能?”如果您是注册开发者。
First of all, if the change is as trivial as changing the background color, and you want to change the default color, you must have hundreds (or at least dozens) of labels, which tells me that the real problem is somewhere else.
However, if you really want to do this, I can think of a few ways:
Subclass UILabel and override initWithCoder or in your subclass to change the color. Then change your labels' classes to point to your subclass, which isn't really easier than changing the color, and you won't even see the result in IB.
If this was any other UIView subclass, overriding drawRect in a protocol could have worked. To get it to work for a UILabel, you probably have to do the text drawing too, and you still won't see the result in IB. Just listing your options.
If you really want to see the result in IB, you can go crazy and create an IB plugin, which could be the definition of killing a fly with a sledgehammer: http://cocoawithlove.com/2009/07/custom-views-in-interface-builder-using.html
Finally, you can wait for iOS 5 and UIAppearance. Check out "What's new in iOS 5?" if you're a registered developer.