为视图中的所有标签设置自定义字体

发布于 2024-12-29 11:42:26 字数 161 浏览 3 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白昼 2025-01-05 11:42:26

您可以使用 IBOutletCollection。创建一个集合并将所有标签连接到 IB 中的该集合。然后在代码中只需使用 setValue forKey 即可。不知道它是否更有效,但您不必循环子视图。

.h
IBOutletCollection(UILabel) NSArray *labels;

.m
UIFont *newFont = [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:14];
[labels setValue:newFont forKey:@"font"]; 

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.

.h
IBOutletCollection(UILabel) NSArray *labels;

.m
UIFont *newFont = [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:14];
[labels setValue:newFont forKey:@"font"]; 
一直在等你来 2025-01-05 11:42:26

您可以循环遍历相关视图的 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 (send isKindOfClass:[UILabel class]). If it is, you can set the font property to a suitable font object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文