Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a gradient to the text of a UILabel, but not the background?

hey, I want to be able to have a gradient fill on the text in a UILabel I know about CGGradient but i dont know how i would use it on a UILabel's text

i found this on google but i cant manage to get it to work

http://silverity.livejournal.com/26436.html

like image 954
DotSlashSlash Avatar asked Aug 12 '09 13:08

DotSlashSlash


People also ask

Can we apply gradient on text?

To add a gradient overlay to a text element, we need to set three different CSS properties to the text we want to style: background-image: <gradient> background-clip: text. text-fill-color: transparent.


1 Answers

I was looking for a solution and DotSlashSlash has the answer hidden in one of the comments!

For the sake of completeness, the answer and the simplest solution is:

UIImage *myGradient = [UIImage imageNamed:@"textGradient.png"]; myLabel.textColor   = [UIColor colorWithPatternImage:myGradient]; 
like image 61
Bach Avatar answered Oct 14 '22 12:10

Bach