Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradient on a UILabel? [duplicate]

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.

like image 768
Bigfoot11 Avatar asked Sep 14 '25 18:09

Bigfoot11


2 Answers

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

like image 69
Manu Mateos Avatar answered Sep 16 '25 09:09

Manu Mateos


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.

like image 22
evansjohnson Avatar answered Sep 16 '25 07:09

evansjohnson