siwft 开发快捷操作 扩展颜色操作类,16进制数字直接转换成对应的RGB。直接操作颜色

//
//  UiColorExtension.swift
//  geekTime
//
//  Created by liuan on 2020/9/14.
//  Copyright © 2020 liuan. All rights reserved.
//

import Foundation
import UIKit
extension UIColor{
    static func hexColor(_ hexValue:Int,alpahValue:Float)->UIColor{
        return UIColor(red: CGFloat(hexValue & 0xFF0000 >> 16 / 255), green: CGFloat(hexValue & 0x00FF00 >> 8 / 255), blue: CGFloat(hexValue & 0x0000FF  / 255), alpha: CGFloat(alpahValue))
    }
    
    static func hexColor(_ hexValue:Int)->UIColor{
        return hexColor(hexValue,alpahValue: 1)
         
     }

    convenience init(_ hexValue:Int,alpahValue:Float) {
       
        self.init(red: CGFloat(hexValue & 0xFF0000 >> 16 / 255) ,green: CGFloat(hexValue & 0x00FF00 >> 8 / 255), blue: CGFloat(hexValue & 0x0000FF  / 255), alpha: CGFloat(alpahValue))
    }
    
    convenience init(_ hexValue:Int) {
        self.init(hexValue,alpahValue:1)
    }
}

 

你可能感兴趣的:(#,swift)