美文网首页
swift 字间距 计算高度

swift 字间距 计算高度

作者: 艾欧尼亚 | 来源:发表于2020-03-21 18:18 被阅读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()
        }
    

    相关文章

      网友评论

          本文标题:swift 字间距 计算高度

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