【问题标题】:Text align paragraph in rich UITextView with CoreText?富UITextView中的文本与CoreText对齐段落?
【发布时间】: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


    【解决方案1】:

    尝试创建和使用 NSParagraphStyle。 (相应地,您也应该使用NSParagraphStyleAttributeName 作为属性名称,尽管行为表明名称是相同的。)

    NSParagraphStyle 是 iOS 6 中的新功能。我不知道对针对旧版本的开发人员有何建议。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-03
      • 1970-01-01
      • 1970-01-01
      • 2012-09-16
      • 1970-01-01
      • 1970-01-01
      • 2016-11-08
      • 1970-01-01
      相关资源
      最近更新 更多