gpt4 book ai didi

ios - NSMutableAttributedString 垂直对齐

转载 作者:可可西里 更新时间:2023-11-01 04:02:33 30 4
gpt4 key购买 nike

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

最佳答案

但我已经尝试过垂直它对我来说工作正常,下面是屏幕截图让我知道如果我错了,下面还附有代码:--

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

关于ios - NSMutableAttributedString 垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19441972/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com