Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the background color of a UILabel with swift

In my Xcode project, I want to change/set the background color of a label using Swift. How can I do that simply?

I have this, but it only works for buttons.

label.backgroundColor = UIColor(red: 0/255, green: 159/255, blue: 184/255, alpha: 1.0)
like image 462
Nathan C Avatar asked Feb 17 '17 02:02

Nathan C


1 Answers

Updated for swift 3:

1] if you want to change the UILabel background color, then used below simple lines of code:

yourLabelName.backgroundColor = UIColor.green

Note:- You can also be used different types of standard colors, UIColor.white, UIColor.red...

2] If you want to change the UILabel text color, then used below simple lines of code:

   yourLabelName.textColor = UIColor.red

// Enjoy Coding...!

like image 183
Kiran Jadhav Avatar answered Oct 06 '22 00:10

Kiran Jadhav