在iOS 6应用程序中,我将UITextView设置为接受属性字符串。
如何更改段落的文本对齐方式(左-右-中心-对齐)?
如下代码:
NSMutableAttributedString *mutableAttributeString = [textView.attributedText mutableCopy];
CTTextAlignment alignment = kCTCenterTextAlignment;
CTParagraphStyleSetting settings[] = {kCTParagraphStyleSpecifierAlignment, sizeof(alignment), &alignment};
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(settings, sizeof(settings) / sizeof(settings[0]));
CFAttributedStringSetAttribute((CFMutableAttributedStringRef)mutableAttributeString, CFRangeMake(0, CFAttributedStringGetLength((CFMutableAttributedStringRef)mutableAttributeString)), kCTParagraphStyleAttributeName, paragraphStyle);
CFRelease(paragraphStyle);
textView.attributedText = mutableAttributeString;
在最后一行崩溃:
-[__ NSCFType headIndent]:无法识别的选择器已发送到实例0x1559b2d0
最佳答案
尝试改为创建和使用NSParagraphStyle。 (相应地,您也应该使用NSParagraphStyleAttributeName
作为属性名称,尽管这种行为表明名称是相同的。)
NSParagraphStyle在6中是iOS的新功能。我不知道对面向较早版本的开发人员有何建议。
关于ios - 使用CoreText将丰富的UITextView中的文本对齐段落?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12583634/