美文网首页
swift:颜色的宏UIColor RGB16

swift:颜色的宏UIColor RGB16

作者: 半江瑟瑟 | 来源:发表于2016-09-22 17:22 被阅读164次
    extension LECommon{
    //rbg转UIColor(16进制)
    class func RGB16(rgbValue:Int) -> UIColor {
        return UIColor.init(colorLiteralRed:((Float)((rgbValue & 0xFF0000) >> 16))/255.0, green: ((Float)((rgbValue & 0xFF00) >> 8))/255.0, blue: ((Float)(rgbValue & 0xFF))/255.0 , alpha: 1.0)
    }
    
    //rbg转UIColor(16进制)带透明度
    class func RGBA16(rgbaValue:Int) -> UIColor {
        return UIColor.init(colorLiteralRed:((Float)((rgbaValue & 0xFF0000) >> 16))/255.0, green: ((Float)((rgbaValue & 0xFF00) >> 8))/255.0, blue: ((Float)(rgbaValue & 0xFF))/255.0 , alpha: ((Float)((rgbaValue & 0xFF000000) >> 24))/255.0)
    }
    
    class func RGBColor(r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat) -> UIColor {
        return UIColor.init(red: (r/255.0), green: (g/255.0), blue: (b/255.0), alpha: a)
    }
    }
    

    参考文章:
    http://www.cnblogs.com/PLA-Artillery/p/5809414.html
    http://21lovetong.blog.51cto.com/9944813/1615797
    http://www.jianshu.com/p/345fa430e44e

    相关文章

      网友评论

          本文标题:swift:颜色的宏UIColor RGB16

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