2012-09-25 100 views
1

在iOS 6應用程序中,我將UITextView設置爲接受屬性字符串。將文本與豐富的UITextView中的段落與CoreText對齊?

如何更改段落的文本對齊(左 - 右 - 中心對齊)?

下面的代碼:在與最後一行

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

回答

4

嘗試創建和使用NSParagraphStyle代替。 (相應地,對於屬性名稱,也應該使用NSParagraphStyleAttributeName,雖然行爲表明這些名稱是相同的。)

NSParagraphStyle是iOS中新增的iOS版本。我不知道如何爲面向舊版本的開發人員提供建議。