如何将文本对齐属性添加到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];