gpt4 book ai didi

ios - MultiLine UIlabel 不显示所有文本?

转载 作者:可可西里 更新时间:2023-11-01 00:37:31 26 4
gpt4 key购买 nike

我想根据我使用过的文本显示标签大小uilabel 行属性号。

lbl.numberoflines = 0;

但它只显示三行,然后显示...。并非所有文本都显示。

当我给出的行数超过 3 时,它会在标签中显示该行。

感谢帮助

最佳答案

试试这个

lbl.lineBreakMode = UILineBreakModeWordWrap;

lbl.numberOfLines = 0;

如果要手动计算高度

 lbl.numberOfLines = 0; // allows label to have as many lines as needed
lbl.text =@"xxxxxxxxxxxxxxxxxxxxxx";
CGSize labelSize = [ lbl.text sizeWithFont: lbl.font constrainedToSize:CGSizeMake(300, 300) lineBreakMode:NSLineBreakByWordWrapping];

// set the frame of labels here

否则你可以直接放在属性中

enter image description here

swift3

lbl.lineBreakMode = .byWordWrapping
lbl.numberOfLines = 0

// allows label to have as many lines as needed
lbl.text = "xxxxxxxxxxxxxxxxxxxxxx"
var labelSize = lbl.text.size(with: lbl.font, constrainedToSize: CGSize(width: 300, height: 300), lineBreakMode: .byWordWrapping)
// set the frame of labels here }

关于ios - MultiLine UIlabel 不显示所有文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31316087/

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