我可以为 Interface Builder 使用通用样式资源吗?如果可以,如何使用?
是否可以在 Interface Builder 中定义通用样式(例如颜色或字体大小),然后在不同的界面或 NIB 中选取它?
基本上,我想在一个位置为 iPhone 应用程序中的所有标签定义一种恒定颜色,然后为所有标签(甚至跨不同的 NIB)增加该颜色。
这可能吗?如果可以我该如何实施?
Is it possible to define a common style such as a color or font size in Interface Builder and then pick it up in different interfaces or NIBs?
Basically I want to define a constant color in one place for all the labels in my iPhone application, then up that color for all labels, even across different NIBs.
Is this possible? If so how can I implement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IB 中没有内置任何东西可以做到这一点。最接近的方法是将颜色拖到颜色选择器底部的小框中之一,这样可以保存它以供将来使用(稍后您可以将其从框中拖到顶部的颜色池中。)
如果如果您确实想在一个地方定义颜色或字体样式并使其更改在所有地方生效,则必须在相关的 -awakeFromNib 方法中的代码中执行此操作。一种方法是编写一个函数来遍历视图层次结构,查找所有标签视图,并对它们应用颜色/字体。
There's nothing built into IB for doing that. The closest you can come is to drag the color into one of the little boxes as the bottom of the color picker, which saves it for future use (you can later drag it out of the box into the color well at the top.)
If you really want to define a color or font style in one place and have changes to it take effect everywhere, you'll have to do it in code, in the relevant -awakeFromNib method. One way to do it is to write a function that walks through the view hierarchy, finds all the label views, and applies the color/font to them.