名称和尺寸来自 NSFont

发布于 2025-01-04 02:41:46 字数 236 浏览 3 评论 0原文

我试图在互联网上找到一些东西,但现在我没有答案,所以如果你能帮助我那就太好了! 到目前为止,我有一个 NSFont 对象,但我想要字体的名称(如 NSString)和大小,这样我就可以输出它!就像

[NSFont fontWithName:@"Menlo" size:11];

只是倒过来一样,所以我得到了名称“Menlo”和尺寸 11。

感谢帮助! 来自德国的Xcoder

i've tried to find something in the Internet, but right now I don't have an answer, so it would be great if you can help me!
So far I have a NSFont object, but I would like the name (as NSString) and size of the font, so I can output that! It's like

[NSFont fontWithName:@"Menlo" size:11];

only backwards, so I get the name "Menlo" and as size 11.

Thanks for help!
Xcoder from Germany

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

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

发布评论

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

评论(4

如何视而不见 2025-01-11 02:41:46
NSString* fontName = [*yourfont* fontName];
float fontSize = [[[*yourfont* fontDescriptor] objectForKey:NSFontSizeAttribute] floatValue];
NSString* fontName = [*yourfont* fontName];
float fontSize = [[[*yourfont* fontDescriptor] objectForKey:NSFontSizeAttribute] floatValue];
夜唯美灬不弃 2025-01-11 02:41:46

我认为现在是 font.pointSize,而不是 font.systemSize。

I think it's font.pointSize now, not font.systemSize.

九公里浅绿 2025-01-11 02:41:46

字体只是对象。它们具有诸如 fontNamesystemSize 之类的变量。
例如,如果我想知道名为 titleLabel 的 UILabel 的字体和大小,我将使用:

NSLog(@"fontwithName:%@ size:%f", self.titleLabel.font.fontName, self.titleLabel.font .systemSize);

有关更多信息,请参阅 NSFont 类参考。
https://developer. apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSFont_Class/Reference/Reference.html

Fonts are just objects. They have variables like fontName and systemSize.
For example if I wanted to know the font and size of a UILabel named titleLabel I would use:

NSLog(@"fontwithName:%@ size:%f", self.titleLabel.font.fontName, self.titleLabel.font.systemSize);

For more look at the NSFont Class Reference.
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSFont_Class/Reference/Reference.html

故事与诗 2025-01-11 02:41:46

NSFont 的名称和大小是带有 setter 和 getter (@property) 的变量,因此您可以轻松获取它们:

object.fontName;
object.systemSize;

The name and size of NSFont are variables with setters and getters (@property) so you can easily get them:

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