2013-10-18 162 views
6

我有一个文本的椭圆路径。对于填充路径我使用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]; 

但是,这项工作只适用于水平文本对齐。我如何应用垂直对齐?

我有这样的结果: enter image description here

但我需要这样的: enter image description here

回答

0

可是我不得不与垂直它工作正常,我试过了,下面是截图让我知道 如果我错了,也低于是连接代码: -

enter image description here

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

我已经更新了这个问题,现在可能会更清楚 –