swift 计算多行label换行的高度

2023-11-07  本文已影响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)
}

上一篇下一篇

猜你喜欢

热点阅读