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.

1

2 Answers 2

11

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

Sign up to request clarification or add additional context in comments.

1 Comment

since the text will dissapear... A pain in the neck. Creating a custom view is a nice suggestion +1
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.