美文网首页
swift 计算多行label换行的高度

swift 计算多行label换行的高度

作者: 可乐小子 | 来源:发表于2023-11-07 11:46 被阅读0次

static func sizeOfContentLabel(label: UILabel,maxWidth: CGFloat) -> CGSize {
label.numberOfLines = 0
let maxSize: CGSize = CGSizeMake(maxWidth, CGFloat(MAXFLOAT))
let titleSize: CGSize = LabelTool.size(ofStr: label.text, andFont: label.font, andMaxSize: maxSize, andLineBreakMode: .byWordWrapping)
let updateSize : CGSize = CGSizeMake(maxWidth, titleSize.height+1)

    return  updateSize
}

let bottomLabel: UILabel = ZZCustomView.labelWithFont(fontSize: 15, text: bottomName, textColor: HexColor(0x333333))
let bottomSize: CGSize = ZZCustomView.sizeOfContentLabel(label: bottomLabel, maxWidth: ScreenW - 2 * 43)
self.addSubview(bottomLabel)
bottomLabel.textAlignment = .center
bottomLabel.snp.makeConstraints { make in
make.centerX.equalTo(topIconView)
make.top.equalTo(titleLabel.snp.bottom).offset(11)
make.size.equalTo(bottomSize)
}

相关文章

网友评论

      本文标题:swift 计算多行label换行的高度

      本文链接:https://www.haomeiwen.com/subject/cjcfwdtx.html