iphone - 如何为 UILabel 的文本而不是背景添加渐变?

标签 iphone objective-c core-graphics uilabel gradient

嘿,我希望能够对 UILabel 中的文本进行渐变填充我知道 CGGradient,但我不知道如何在 UILabel 的文本上使用它

我在谷歌上找到了这个,但我无法让它工作

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

最佳答案

我一直在寻找解决方案,而 DotSlashSlash 在其中一条评论中隐藏了答案!

为了完整起见,答案和最简单的解决方案是:

UIImage *myGradient = [UIImage imageNamed:@"textGradient.png"];
myLabel.textColor   = [UIColor colorWithPatternImage:myGradient];

关于iphone - 如何为 UILabel 的文本而不是背景添加渐变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1266179/

相关文章:

iphone - 如何上传从 UIImagePickerController 获取的图像

ios - 如何对 tableview 行执行操作以及如何在其中添加添加披露指示符?

iphone - 向 UIDatePicker 添加按钮

ios - 在 UIView2 上方显示 UIView1,但按输入方式将 UIView2 置于 UIView1 上方

ios - 在 iOS 应用程序中使用 Apple Maps 是免费的吗?

objective-c - ParseKit.framework 无法工作,找不到 Foundation.h

ios - 为什么解雇ViewControllerAnimated : completion: method can't dealloc view controller

ios - 如何使用为其他UIViewController生成UITableView?

iphone - iOS 中的四点渐变

Swift CoreGraphics UIBezierPath 不会正确填充内部