我正在学习swift
现在将#define转换为swift
#define HColorToRGB(rgbValue,alphaValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:alphaValue]
如何将Obj-C定义转换为Swift代码?
感谢阅读干杯
答案 0 :(得分:2)
func HColorToRGB(rgbValue: Int, alpha: Float) -> UIColor {
return UIColor(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0xFF00) >> 8) / 255.0,
blue: CGFloat(rgbValue &0xFF) / 255.0,
alpha: CGFloat(alpha)
)
}
yourView.backgroundColor = HColorToRGB("passyourValue","alphaValue")