NSAttributedString - 获取字体属性 [英] NSAttributedString - get font attributes

查看:453
本文介绍了NSAttributedString - 获取字体属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取有关我的属性字符串的信息,但无法弄清楚如何。我收到这本词典:

I need to get info about my attributed string but can't figure out how. I'm getting this dictionary:

2013-11-04 18:06:10.628 App[1895:60b] {
    NSColor = "UIDeviceWhiteColorSpace 0.3 1";
    NSFont = "<UICTFont: 0x17d8d4c0> font-family: \".HelveticaNeueInterface-MediumP4\"; font-weight: bold; font-style: normal; font-size: 17.00pt";
    NSUnderline = 0;
}

很容易检查下划线:

[attrs objectForKey:@"NSUnderline"]

但如何获取字体信息,如字体样式,字体重量等。

But how to get info about font like the font-style, font-weight etc.

感谢您的帮助

推荐答案

您可以从以下字体获取字体:

You get the font from:

UIFont *font = attrs[NSFontAttributeName];

问题在于确定它是否为粗体。没有财产。唯一的选择是查看字体的 fontName ,看看是否包含Bold或其他类似术语。并非所有粗体字体在名称中都有粗体。

The issue is determining whether it is bold or not. There is no property for that. The only option is to look at the fontName of the font and see if contains "Bold" or some other similar term. Not all bold fonts have "Bold" in the name.

同样的问题适用于确定字体是斜体还是注释。您必须查看 fontName 并查找Italic或Oblique等内容。

The same issue applies for determining of the font is italic or note. You have to look at the fontName and look for things like "Italic" or "Oblique".

这篇关于NSAttributedString - 获取字体属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆