//根据文字获取高度
func caculateHeight(commemt : String, fontSize : CGFloat, showWidth : CGFloat) -> CGFloat {
let font = UIFont.systemFont(ofSize: fontSize)
let size = commemt.boundingRect(with: CGSize(), options: .usesFontLeading, attributes: [NSAttributedString.Key.font : font], context: nil)
return (size.height - 2 * size.origin.y) * (size.width / showWidth)
}
swift_动态获取文字高度
最新推荐文章于 2022-04-02 10:50:50 发布
本文介绍了一个使用Swift语言编写的函数,该函数能够根据输入的文字、字体大小和显示宽度计算出文本的高度。通过调整字体和宽度参数,可以灵活地应用于不同场景下的文本布局需求。

1893

被折叠的 条评论
为什么被折叠?



