【发布时间】:2012-09-25 22:53:09
【问题描述】:
在 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
【问题讨论】:
标签: ios uitextview core-text nsattributedstring text-alignment