为视图中的所有标签设置自定义字体
在 Xcode 4 中,如果操作系统中未安装字体或未出现在 IB 的字体列表中,则无法通过 Interface Builder 设置视图标签的字体系列。
由于某些视图中的所有标签都使用相同的字体,因此我需要知道是否有一种简单快捷的方法将所有标签设置为相同的字体系列,而不是逐个设置其系列字体。
In Xcode 4, it's not possible to set the Font Family of a view's labels through Interface Builder if the font is not installed in the OS or doesn't appear in the list of fonts in IB.
Since all the labels in certain views use the same font, I need to know if there's a simple and fast way of setting all of them to the same font family, instead of going one by one setting its family font.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 IBOutletCollection。创建一个集合并将所有标签连接到 IB 中的该集合。然后在代码中只需使用 setValue forKey 即可。不知道它是否更有效,但您不必循环子视图。
You can you use an IBOutletCollection. Create a collection and connect all your labels to it in IB. Then in code just use setValue forKey. No idea if it's more efficient or not, but you don't have to loop through subviews.
您可以循环遍历相关视图的 subviews 数组属性中的每个条目。对于每一个,检查它是否是
UILabel
(发送isKindOfClass:[UILabel class]
)。如果是,您可以将font
属性设置为合适的字体对象。You could loop over each entry in the subviews array property of the view in question. For every one, check if it is a
UILabel
(sendisKindOfClass:[UILabel class]
). If it is, you can set thefont
property to a suitable font object.