UILabel中的多行文本有没有办法让多行文本在UILabel中,UITextView或者我应该使用第二行?
3 回答
BIG阳
TA贡献1859条经验 获得超6个赞
方法1:
extension UILabel {//Write this extension after close brackets of your class func lblFunction() { numberOfLines = 0 lineBreakMode = .byWordWrapping//If you want word wraping //OR lineBreakMode = .byCharWrapping//If you want character wraping }}
现在打电话就像这样
myLbl.lblFunction()//Replace your label name
EX:
Import UIKitclass MyClassName: UIViewController {//For example this is your class. override func viewDidLoad() { super.viewDidLoad() myLbl.lblFunction()//Replace your label name }}//After close of your class write this extension.extension UILabel {//Write this extension after close brackets of your class func lblFunction() { numberOfLines = 0 lineBreakMode = .byWordWrapping//If you want word wraping //OR lineBreakMode = .byCharWrapping//If you want character wraping }}
方法2:
编程
yourLabel.numberOfLines = 0yourLabel.lineBreakMode = .byWordWrapping//If you want word wraping//ORyourLabel.lineBreakMode = .byCharWrapping//If you want character wraping
方法3:
通过故事板
要显示多行设置为0(零),这将在标签中显示多行。
如果要显示n行,请设置n。
见下面的屏幕。
如果要为标签设置最小字体大小单击“自动收缩”和“选择最小字体大小”选项
见下面的屏幕
这里设置最小字体大小
EX:9(在此图中)
如果您的标签在此时获得更多文字,您的标签文字将缩小至9
慕尼黑的夜晚无繁华
TA贡献1864条经验 获得超6个赞
斯威夫特4:
label.lineBreakMode = .byWordWrapping
label.numberOfLines = 0
label.translatesAutoresizingMaskIntoConstraints = false
label.preferredMaxLayoutWidth = superview.bounds.size.width - 10
- 3 回答
- 0 关注
- 865 浏览
添加回答
举报
0/150
提交
取消