Vertical Alignment NSMutableAttributedString

I have an ellipse path for text. For the fill path, I used 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 only works for horizontal text alignment. How can I apply vertical offset?

I have this result: enter image description here

But I need this: enter image description here

+6
source share
1 answer

But I tried with vertical, it works great for me, Below is a screenshot. Let me know. if I am mistaken, and below is the code: -

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

Source: https://habr.com/ru/post/956214/


All Articles