gpt4 book ai didi

objective-c - NSMutableAttributedString 自动换行

转载 作者:技术小花猫 更新时间:2023-10-29 11:20:19 26 4
gpt4 key购买 nike

我有 NSMutableAttributedString 并且字符串很长。我想在 UIlabel 上显示时进行自动换行。如果它是 NSString,我会继续做这样的事情, Dynamic UILabel truncating the text 但是我怎么能用 NSAttributedString 呢?完成后,我需要根据标签大小调整 View 大小。

最佳答案

lineBreakMode 属性在 iOS 6 中并未弃用。它只是更改了常量的名称。旧常量已弃用,但仍然可用。即使您部署到较旧的 iOS,也可以使用新常量,因为常量只是枚举值。旧名称和新名称具有相同的值。所以,只需设置 yourlabelname.lineBreakMode = NSLineBreakByTruncatingTail。

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
[attributedStr addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:NSMakeRange(0,[attributedStr length])];

关于objective-c - NSMutableAttributedString 自动换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12080942/

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