// 通过 red 、 green 、blue 、alpha 颜色数值
publicletRGBAlpa:((Float,Float,Float,Float) ->UIColor) = { (r:Float, g:Float, b:Float, a:Float) ->UIColorin
returnUIColor.init(red:CGFloat(CGFloat(r)/255.0), green:CGFloat(CGFloat(g)/255.0), blue:CGFloat(CGFloat(b)/255.0), alpha:CGFloat(a))
}
// 通过 十六进制与alpha来设置颜色值 HexRGBAlpha(0xe47833,1)
publicletHexRGBAlpha:((Int,Float) ->UIColor) = { (rgbValue :Int, alpha :Float) ->UIColorin
returnUIColor(red:CGFloat(CGFloat((rgbValue & 0xFF0000) >> 16)/255), green:CGFloat(CGFloat((rgbValue & 0xFF00) >> 8)/255), blue:CGFloat(CGFloat(rgbValue & 0xFF)/255), alpha:CGFloat(alpha))
}
extension String {
/// 计算文本的高度
functextHeight(fontSize:CGFloat,width:CGFloat) ->CGFloat{
returnself.boundingRect(with:CGSize(width: width, height:CGFloat(MAXFLOAT)), options: .usesLineFragmentOrigin, attributes: [.font:UIFont.systemFont(ofSize: fontSize)], context:nil).size.height
}
/// 计算文本宽度
functextWidth(fontSize:CGFloat,height:CGFloat) ->CGFloat{
returnself.boundingRect(with:CGSize(width:CGFloat(MAXFLOAT), height:height ), options: .usesLineFragmentOrigin, attributes: [.font:UIFont.systemFont(ofSize: fontSize)], context:nil).size.width
}
/// 计算加粗文本的高度
functextBlodHeight(fontSize:CGFloat,width:CGFloat) ->CGFloat{
returnself.boundingRect(with:CGSize(width: width, height:CGFloat(MAXFLOAT)), options: .usesLineFragmentOrigin, attributes: [.font:UIFont.boldSystemFont(ofSize: fontSize)], context:nil).size.height
}
/// 计算加粗文本宽度
functextBlodWidth(fontSize:CGFloat,height:CGFloat) ->CGFloat{
returnself.boundingRect(with:CGSize(width:CGFloat(MAXFLOAT), height:height ), options: .usesLineFragmentOrigin, attributes: [.font:UIFont.boldSystemFont(ofSize: fontSize)], context:nil).size.width
}
}
喜欢的话,可以看我其他文章哦,别忘了点歌👍哦
网友评论