How can I use UIColorFromRGB in Swift?

后端 未结 20 811
一生所求
一生所求 2020-12-04 05:48

In Objective-C, we use this code to set RGB color codes for views:

#define UIColorFromRGB(rgbValue)        
[UIColor colorWithRed:((float)((rgbValue & 0x         


        
20条回答
  •  孤城傲影
    2020-12-04 06:02

    In Swift3, if you are starting with a color you have already chosen, you can get the RGB value online (http://imagecolorpicker.com) and use those values defined as a UIColor. This solution implements them as a background:

        @IBAction func blueBackground(_ sender: Any) {
            let blueColor = UIColor(red: CGFloat(160/255), green: CGFloat(183.0/255), blue: CGFloat(227.0/255), alpha: 1)
            view.backgroundColor = blueColor
    

    @Vadym mentioned this above in the comments and it is important to define the CGFloat with a single decimal point

提交回复
热议问题