Tag: core text

核心文本 – NSAttributedString行高正确?

Core Text的行距完全在黑暗中。 我正在使用NSAttributedString,我指定了以下属性: – kCTFontAttributeName – kCTParagraphStyleAttributeName 从这个CTFrameSetter被创build并绘制到上下文。 在段落样式属性中,我想指定线的高度。 当我使用kCTParagraphStyleSpecifierLineHeightMultiple每行接收填充文本的顶部,而不是在这个高度的中间显示文本。 当我使用kCTParagraphStyleSpecifierLineSpacing一个填充添加到文本的底部。 请帮助我使用文本(字形)在该高度的中间达到指定的行高度,而不是坐在底部或顶部的文本。 如果不沿着明确创buildCTLine等的路线,这是不可能的?

NSAttributedString添加文本alignment

我如何添加文本alignment属性到NSAttributedString来居中文本? 编辑:我做错了什么? 似乎没有改变路线。 CTParagraphStyleSetting setting; setting.spec = kCTParagraphStyleSpecifierAlignment; setting.valueSize = kCTCenterTextAlignment; CTParagraphStyleSetting settings[1] = { {kCTParagraphStyleSpecifierAlignment, sizeof(CGFloat), &setting}, }; CTParagraphStyleRef paragraph = CTParagraphStyleCreate(settings, sizeof(setting)); NSMutableAttributedString *mutableAttributed = [[NSMutableAttributedString alloc] initWithAttributedString:self.attributedString]; [mutableAttributed addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:(NSObject*)paragraph ,(NSString*) kCTParagraphStyleAttributeName, nil] range:_selectedRange];

在iOS中将HTML转换为NSAttributedString

我正在使用UIWebView一个实例来处理一些文本和正确的颜色,它给出的结果作为HTML,而不是显示在UIWebView我想显示它使用Core Text与NSAttributedString 。 我能够创build和绘制NSAttributedString但我不确定如何转换和映射到属性string的HTML。 我知道在Mac OS X下, NSAttributedString有一个initWithHTML:方法,但是这只是一个Mac的附加,不适用于iOS。 我也知道还有一个类似的问题,但是没有答案,我虽然会再试一次,看是不是有人创造了这样做的方法,如果可以的话,是否可以分享。