我想根据标签中的文字显示标签尺寸
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

否则你可以直接放在属性

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/

10-09 07:03