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

DotSlashSlash picture DotSlashSlash · Aug 12, 2009 · Viewed 38.9k times · Source

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

Answer

Bach picture Bach · Dec 29, 2010

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];