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 回答