swift 高度自适应方法

来源:互联网 发布:手机淘宝联盟推广教程 编辑:程序博客网 时间:2024/06/13 04:05

   func ZuoHeightWithConstrainedWidth ( width : CGFloat , font :  UIFont,  str :NSString )  ->  CGFloat  {

    let constraintRect = CGSize ( width : width , height : CGFloat . max )

    

    let boundingBox =  str.boundingRectWithSize ( constraintRect , options : NSStringDrawingOptions . UsesLineFragmentOrigin , attributes :  [NSFontAttributeName : font ], context : nil )

    

   //返回boundingBox的。高度

        return boundingBox.height

    }

0 0
原创粉丝点击