考虑我有以下文本UILabel
(一长行动态文本):
由于外星军队的数量远远超过团队,玩家必须利用后世界末日的世界来发挥自己的优势,例如在垃圾箱、柱子、汽车、瓦砾和其他物体后面寻找掩护。
我想调整大小UILabel's
高度,以便文本可以适合。我正在使用以下属性UILabel
使其中的文本换行。
myUILabel.lineBreakMode = UILineBreakModeWordWrap;
myUILabel.numberOfLines = 0;
如果我没有朝着正确的方向前进,请告诉我。谢谢。
sizeWithFont constrainedToSize:lineBreakMode:
是要使用的方法。下面是如何使用它的示例:
//Calculate the expected size based on the font and linebreak mode of your label
// FLT_MAX here simply means no constraint in height
CGSize maximumLabelSize = CGSizeMake(296, FLT_MAX);
CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font constrainedToSize:maximumLabelSize lineBreakMode:yourLabel.lineBreakMode];
//adjust the label the the new height.
CGRect newFrame = yourLabel.frame;
newFrame.size.height = expectedLabelSize.height;
yourLabel.frame = newFrame;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)