美文网首页iOS Developer
swift 16进制颜色转换和计算文本高度

swift 16进制颜色转换和计算文本高度

作者: 瞪凳 | 来源:发表于2016-10-10 14:24 被阅读64次
  1. 16进制的颜色转换
    class func rgbaColor(rgb:Int,alphe:CGFloat) -> UIColor
    {
    return UIColor (red:((CGFloat)((rgb & 0xFF0000)>>16))/255.0,green:((CGFloat)((rgb & 0xFF00)>>8))/255.0,blue:((CGFloat)(rgb & 0xFF))/255.0,alpha:alphe)
    }

  2. 计算文本的高度
    class func textHeight(textString:String,textWidth:CGFloat,textHeight:CGFloat,textFont:Float) -> CGSize {
    let size = CGSize(width:textWidth,height:textHeight)
    var size2 = CGSize()

     size2 = textString.boundingRect(with: size, options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: NSDictionary(object:UIFont.systemFont(ofSize: CGFloat(textFont)), forKey: NSFontAttributeName as NSCopying) as? [String : Any] ,context: nil).size 
     
     return size2
     }

相关文章

网友评论

    本文标题:swift 16进制颜色转换和计算文本高度

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