gpt4 book ai didi

ios - UILabel 文本行设置为方形排列 iOS

转载 作者:行者123 更新时间:2023-11-30 13:11:31 26 4
gpt4 key购买 nike

我想将标签文本排列在标签文本行的方形 View 格式上,并且标签有一些短单词,有些比标签文本的其他单词更大,所以请参阅此演示图像 Sqaure shape Image

最佳答案

尝试使用 NSAttributedString 希望支持多种字体和文本大小,并使用\n 返回下一行。

    NSDictionary *italicAttrs = @{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:16], NSForegroundColorAttributeName : [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]};

NSDictionary *defaultAttrs = @{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Medium" size:16], NSForegroundColorAttributeName : [UIColor blackColor]};

NSDictionary *arrowAttrs = @{NSFontAttributeName : [UIFont fontWithName:@"AlNile-Bold" size:20], NSForegroundColorAttributeName : [UIColor grayColor]};


NSMutableAttributedString *labelText = [[NSMutableAttributedString alloc] init];

NSAttributedString *from = [[NSAttributedString alloc] initWithString:@"From: " attributes:italicAttrs];

NSAttributedString *content = [[NSAttributedString alloc] initWithString:@"Me\n" attributes:defaultAttrs];

NSAttributedString *arrow = [[NSAttributedString alloc] initWithString:@"Ok" attributes:arrowAttrs];


[labelText appendAttributedString:from];
[labelText appendAttributedString:content];
[labelText appendAttributedString:arrow];

关于ios - UILabel 文本行设置为方形排列 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38673722/

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