Objective-c
You must specify values ββfrom 0 to 1.0. Divide the RGB values ββby 255.
myLabel.textColor= [UIColor colorWithRed:(160/255.0) green:(97/255.0) blue:(5/255.0) alpha:1] ;
Update:
You can also use this macro.
#define Rgb2UIColor(r, g, b) [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:1.0]
and you can call any of your classes like this
myLabel.textColor = Rgb2UIColor(160, 97, 5);
Swift
This is normal color syntax.
myLabel.textColor = UIColor(red: (160/255.0), green: (97/255.0), blue: (5/255.0), alpha: 1.0)
Swift is not very friendly with macros
Complex macros are used in C and Objective-C, but have no analogues in Swift. Complex macros are macros that do not define constants, including parentheses, function macros. You use complex macros in C and Objective-C to avoid typing restrictions or to avoid renaming large amounts of template code. However, macros can debug and reorganize. In Swift, you can use functions and generics to achieve the same results without any compromise. Therefore, complex macros that are in the C and Objective-C source files are not available for your Swift code.
So we use the extension for this
extension UIColor { convenience init(_ r: Double,_ g: Double,_ b: Double,_ a: Double) { self.init(red: r/255, green: g/255, blue: b/255, alpha: a) } }
You can use it as
myLabel.textColor = UIColor(160.0, 97.0, 5.0, 1.0)