1

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

4

1 に答える 1

4

代わりに NSParagraphStyle を作成して使用してみてください。(対応NSParagraphStyleAttributeNameして、属性名にも を使用する必要がありますが、動作は名前が同じであることを示唆しています。)

NSParagraphStyle は 6 の iOS の新機能です。古いバージョンをターゲットにしている開発者に何を提案すればよいかわかりません。

于 2012-09-25T14:53:09.433 に答える