swift 字间距 计算高度

2020-03-21  本文已影响0人  艾欧尼亚
func nameHeight() {
        let str:String = "斯蒂芬斯蒂芬斯蒂芬斯蒂芬";
          
        var attrButes:[NSAttributedString.Key : Any]! = nil;
        let paraph = NSMutableParagraphStyle()
        paraph.lineSpacing = 10
        attrButes = [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 13.5),NSAttributedString.Key.paragraphStyle:paraph]
          
        let size:CGRect = str.boundingRect(with: CGSize(width: 200, height: CGFloat.greatestFiniteMagnitude), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: attrButes, context: nil)
          
        content.attributedText = NSAttributedString(string: str, attributes: attrButes)
        content.numberOfLines = 0
        content.sizeToFit()
    }
上一篇下一篇

猜你喜欢

热点阅读