6

テキストの楕円パスがあります。フィル パスには、NSMutableAttributedString を使用しました。

UIFont *font = [UIFont fontWithName:@"font name" size:15];
NSMutableParagraphStyle *mutParaStyle=[[NSMutableParagraphStyle alloc] init];

[mutParaStyle setAlignment:NSTextAlignmentCenter];
[mutParaStyle setLineBreakMode:NSLineBreakByWordWrapping];

NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:font
                                 ,NSFontAttributeName,mutParaStyle ,NSParagraphStyleAttributeName,nil]; 

NSMutableAttributedString  *strText = [[NSMutableAttributedString alloc] initWithString:text attributes:attrsDictionary];

ただし、これは水平方向のテキスト配置に対してのみ機能します。垂直方向の配置を適用するにはどうすればよいですか?

私はこの結果を持っています: ここに画像の説明を入力

しかし、私はこれが必要です: ここに画像の説明を入力

4

1 に答える 1

0

しかし、私は垂直方向で試してみましたが、私にとっては問題なく動作しています。以下はスクリーンショットです。間違っている場合はお知らせください。また、以下にコードが添付されています:--

ここに画像の説明を入力

NSString *allTheText = [tv string];
NSFont *font = [NSFont fontWithName:@"Helvetica" size:24];
NSMutableParagraphStyle *mutParaStyle=[[NSMutableParagraphStyle alloc] init];

[mutParaStyle setAlignment:kCTTextAlignmentRight];
[mutParaStyle setLineBreakMode:NSLineBreakByWordWrapping];

NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:font
                                 ,NSFontAttributeName,mutParaStyle ,NSParagraphStyleAttributeName,nil];

NSMutableAttributedString  *strText = [[NSMutableAttributedString alloc] initWithString:allTheText attributes:attrsDictionary];
[tv .textStorage appendAttributedString:strText];
于 2013-10-18T05:56:41.423 に答える