4

I am trying to create a UILabel that will have a gradient background color. I am wondering if there is a way to do this through the interface builder. If not, is there a way to accomplish this programmatically using the Swift programming language?

Any input or suggestions are greatly appreciated.

Thanks in advance.

Bigfoot11
  • 911
  • 2
  • 11
  • 25

2 Answers2

10

You actually can't put directly a gradient layer in a UILabel, since the text will dissapear. See Adding a CGGradient as sublayer to UILabel hides the text of label

You can use an UIView, put your UILabel inside it, and then add the gradient layer to the UIView like this.

How to Apply Gradient to background view of iOS Swift App

Community
  • 1
  • 1
Manu Mateos
  • 174
  • 1
  • 10
4

While not the same question, it seems the answer to this may help:

How to Apply Gradient to background view of iOS Swift App

You have to create a gradient layer and insert it as a sublayer programmatically.

Community
  • 1
  • 1
evansjohnson
  • 452
  • 4
  • 14