1. 程式人生 > >swift - label 的font 設置 文字字體和大小

swift - label 的font 設置 文字字體和大小

light string sys ring can black 1.0 int32 enc

設置字體和顏色

        lab.textColor = UIColor.init(hexColor: "795928")
        lab.font = UIFont.systemFont(ofSize: 32, weight: UIFont.Weight.black)

  

設置html 導圖顏色

extension UIColor {
    
    /// 用十六進制顏色創建UIColor
    ///
    /// - Parameter hexColor: 十六進制顏色 (0F0F0F)
    convenience init(hexColor: String) {
        
        // 存儲轉換後的數值
        var red:UInt32 = 0, green:UInt32 = 0, blue:UInt32 = 0
        
        // 分別轉換進行轉換
        Scanner(string: hexColor[0..<2]).scanHexInt32(&red)
        
        Scanner(string: hexColor[2..<4]).scanHexInt32(&green)
        
        Scanner(string: hexColor[4..<6]).scanHexInt32(&blue)
        
        self.init(red: CGFloat(red)/255.0, green: CGFloat(green)/255.0, blue: CGFloat(blue)/255.0, alpha: 1.0)
    }
    convenience init(hexColor: String, alpha: CGFloat) {
        
        // 存儲轉換後的數值
        var red:UInt32 = 0, green:UInt32 = 0, blue:UInt32 = 0
        
        // 分別轉換進行轉換
        Scanner(string: hexColor[0..<2]).scanHexInt32(&red)
        
        Scanner(string: hexColor[2..<4]).scanHexInt32(&green)
        
        Scanner(string: hexColor[4..<6]).scanHexInt32(&blue)
        
        self.init(red: CGFloat(red)/255.0, green: CGFloat(green)/255.0, blue: CGFloat(blue)/255.0, alpha: alpha)
    }
}

  

swift - label 的font 設置 文字字體和大小