How can I use UIColorFromRGB in Swift?

后端 未结 20 812
一生所求
一生所求 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:18

    The simplest way to add color programmatically is by using ColorLiteral.

    Just add the property ColorLiteral as shown in the example, Xcode will prompt you with a whole list of colors which you can choose. The advantage of doing so is lesser code, add HEX values or RGB. You will also get the recently used colors from the storyboard.

    Example: self.view.backgroundColor = ColorLiteral

提交回复
热议问题