简体   繁体   English

NSMutableAttributedString垂直对齐

[英]NSMutableAttributedString vertical alignment

I have a ellipse path for text. 我有一个文本的椭圆路径。 For fill path I used NSMutableAttributedString: 对于填充路径,我使用了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];

But this work only for horizontal text alignment. 但这只适用于水平文本对齐。 How i can apply vertical aligment? 我如何应用垂直对齐?

I have this result: 我有这个结果: 在此输入图像描述

But I need this: 但我需要这个: 在此输入图像描述

But i have tried with vertical it is working fine for me, Below is the screenshot Let me know if i am wrong and also below is the code attached:-- 但我试过垂直它对我来说工作正常,下面是截图让我知道如果我错了,下面是附加的代码: -

在此输入图像描述

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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM