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

import UIKit
//import SwifterSwift

extension UIColor {
    
    //品牌主色
    static let brandMainColor : UIColor = UIColor(hexString: "#2F7EF6")!
    
    //品牌渐变色
    static let arrBrandGradaterColors : [UIColor] = [UIColor(hexString: "#2274EE")!,UIColor(hexString: "#3A85FC")!]
    
    //品牌主色 16
    static let brandMainColor16 : UIColor = UIColor(hexString: "#2F7EF6",transparency: 0.16)!
    
    //品牌主色 8
    static let brandMainColor8: UIColor = UIColor(hexString: "#2F7EF6",transparency: 0.16)!
    
    //标题/主内容
    static let mainTextColor : UIColor = UIColor(hexString: "#222222")!
    
    //次内容一
    static let subTextColor : UIColor = UIColor(hexString: "#4E4E4E")!
    
    //次内容二
    static let subTextColor2 : UIColor = UIColor(hexString: "#7A7A7A")!
    
    
    //标注内容一
    static let labelTextColor : UIColor = UIColor(hexString: "#D3D3D3")!
    
    //标注内容二
    static let labelTextColor2 : UIColor = UIColor(hexString: "#888F98")!
    
    //成功 color
    static let successColor : UIColor = UIColor(hexString: "#49D2B1")!
    
    //失败 color
    static let failColor : UIColor = UIColor(hexString: "#F81D22")!
    
    //警告 color
    static let warnColor : UIColor = UIColor(hexString: "#FF9900")!
    
    //提示 color
    static let tipsColor : UIColor = UIColor(hexString: "#2F7EF6")!
    
    
    //页面背景
    static let pageBkgColor : UIColor = UIColor(hexString: "#F8F8F8")!
    
    //内容背景色
    static let contentBkgColor : UIColor = UIColor(hexString: "#F8F9FB")!
    
    
    
    
    
    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!
    }
}

