在 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]: unrecognized selector sent to instance 0x1559b2d0