gpt4 book ai didi

ios - NSMutableParagraphStyle 和 NSAttributedString 无法 wordrap

转载 作者:行者123 更新时间:2023-11-29 12:53:02 25 4
gpt4 key购买 nike

我正在尝试使用行间距为 1.25 的多行 NSAttributedString。

NSMutableParagraphStyle *bodyFormat = [[NSMutableParagraphStyle alloc] init];
bodyFormat.alignment = NSTextAlignmentLeft;
//[bodyFormat setLineSpacing:5];
[bodyFormat setLineBreakMode:NSLineBreakByWordWrapping];
//[bodyFormat setMaximumLineHeight:5];
[bodyFormat setLineHeightMultiple:1.25];





NSMutableAttributedString *desc = [[NSMutableAttributedString alloc] initWithString:@"So why to use Lorem Ipsum and why placeholder text is necessary? Naturally, page designs that are made for text documents must contain some text rather than placeholder dots or something else. Howevr, should they contain a proper English words and sentenses almost every reader will deliberately try to interpret it eventually missing the design itself"];
[desc addAttribute:NSParagraphStyleAttributeName value:bodyFormat range:NSMakeRange(0, desc.length)];





UILabel *description = [[UILabel alloc] initWithFrame:CGRectMake(0,
20,
300,
1000)];

description.lineBreakMode = NSLineBreakByWordWrapping;
[description setAttributedText:desc];
[self.view addSubview:description];

这设法产生单行,换行符无效。

我做错了什么?

最佳答案

[bodyFormat setLineSpacing:5];

打破这种行为。

同时设置

description.numberOfLines = 0;

帮助...(描述是 UILabel)

关于ios - NSMutableParagraphStyle 和 NSAttributedString 无法 wordrap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21962650/

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