//
//  UIColor-Extension.swift
//  DouYuUI
//
//  Created by davidhuang on 2022/8/9.
//  Copyright © 2022 davidhuang. All rights reserved.
//

import UIKit
import SwifterSwift

extension UIColor {
    // MARK: - 当前 app 主颜色
    static let mainColor : UIColor = UIColor(hexString: "#46E0BB")!
    static let commonColor100 : UIColor = UIColor(hexString: "#333333",transparency: 1.0)!
    static let commonColor90 : UIColor = UIColor(hexString: "#333333",transparency: 0.9)!
    static let commonColor65 : UIColor = UIColor(hexString: "#333333",transparency: 0.65)!
    static let commonColor45 : UIColor = UIColor(hexString: "#333333",transparency: 0.45)!
    static let commonColor25 : UIColor = UIColor(hexString: "#333333",transparency: 0.25)!
    static let commonColor15 : UIColor = UIColor(hexString: "#333333",transparency: 0.15)!
    static let commonColor10 : UIColor = UIColor(hexString: "#333333",transparency: 0.10)!
    static let commonColor6 : UIColor = UIColor(hexString: "#333333",transparency: 0.06)!
    static let commonColor4 : UIColor = UIColor(hexString: "#333333",transparency: 0.04)!
    static let commonColor3 : UIColor = UIColor(hexString: "#333333",transparency: 0.03)!
    
    static let backgroundColor : UIColor = UIColor(hexString: "#F2F7F6",transparency: 1.0)!
    
    
    static let mainTextColor : UIColor = UIColor(hexString: "#00D19F")!
    static let selectBgColor : UIColor = UIColor(hexString: "#D9FCF7")!
    
    //黑色  50透明
    static let black50Persent : UIColor = UIColor.black.withAlphaComponent(0.5)
    
    
    public convenience init(r : CGFloat, g : CGFloat, b : CGFloat,alpha:CGFloat = 1.0) {
        self.init(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: alpha)
    }
    
    
    // 根据色值生成颜色(无透明度)(格式为0xffffff)
    public convenience init(hex : NSInteger,alpha:CGFloat = 1.0) {
        self.init(red: ((CGFloat)((hex & 0xFF0000) >> 16)) / 255.0, green: ((CGFloat)((hex & 0xFF00) >> 8)) / 255.0, blue: ((CGFloat)(hex & 0xFF)) / 255.0, alpha: alpha)
    }
    
    //生成 对应色值的图片
    public func toImage(width: Double = 1.0, height: Double = 1.0) -> UIImage {
        let rect = CGRect(x: 0.0, y: 0.0, width: width, height: height)
        UIGraphicsBeginImageContext(rect.size)
        let ctx = UIGraphicsGetCurrentContext()
        ctx!.setFillColor(self.cgColor)
        ctx!.fill(rect)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image!
    }
    
}

