更改 UILabel 中的字体名称和粗细(iPhone SDK)

发布于 2024-09-14 17:21:18 字数 252 浏览 3 评论 0原文

也许我看错了地方,但是如何设置 UILabel 的字体及其粗细?

查看文档,似乎只有创建具有给定字体名称和大小的 UIFont 的方法,例如

[UIFont fontWithName:@"Helvetica" size:22])

或创建粗体字体,以及

[UIFont boldSystemFontOfSize:22]

如何将它们一起使用?

Maybe I'm looking at the wrong place, however how do I set an UILabel's font and AND its weight?

Looking at the documentation, there seems to be only methods to create an UIFont with a given font name and size, like

[UIFont fontWithName:@"Helvetica" size:22])

OR create a bold font, with

[UIFont boldSystemFontOfSize:22]

How can I use these both together?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

月亮邮递员 2024-09-21 17:21:18

fontWithName:size: 的文档指出,“...名称包含字体系列和字体的特定样式信息。”

所以你可能想要:

[UIFont fontWithName:@"Helvetica-Bold" size:22];

fontNamesForFamilyName: 可以方便地获取给定系列的可用字体列表。

例如:

NSArray* fontNames = [UIFont fontNamesForFamilyName:@"Helvetica"];
for( NSString* aFontName in fontNames ) {
    NSLog( @"Font name: %@", aFontName );
}

...输出:

Font name: Helvetica-BoldOblique
Font name: Helvetica
Font name: Helvetica-Oblique
Font name: Helvetica-Bold

The documentation for fontWithName:size: states, "...name incorporates both the font family and the specific style information for the font."

So you probably want:

[UIFont fontWithName:@"Helvetica-Bold" size:22];

fontNamesForFamilyName: is handy for getting a list of available fonts for a given family.

For example:

NSArray* fontNames = [UIFont fontNamesForFamilyName:@"Helvetica"];
for( NSString* aFontName in fontNames ) {
    NSLog( @"Font name: %@", aFontName );
}

...which outputs:

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