如何在 iPhone 中为 UILabel 的背景设置渐变颜色 [英] How to set gradient color to the background of UILabel in iPhone
本文介绍了如何在 iPhone 中为 UILabel 的背景设置渐变颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码将渐变颜色设置为标签的背景,但没有影响我做错了什么?代码在这里:
I am using the following code to set the gradient color to the background of label but no effect what i am doing wrong? Code is here:
[self.teamName setTextColor:[UIColor whiteColor]];
[self.teamName setBackgroundColor:[UIColor clearColor]];
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = self.teamName.bounds;
gradientLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor whiteColor]CGColor], (id)[[UIColor blackColor]CGColor], nil];
[self.teamName.layer insertSublayer:gradientLayer atIndex:0];
推荐答案
当我将 CAGradientLayer 插入到主视图时它工作正常.
It working fine when i insert the CAGradientLayer to the main view.
[self.teamName setTextColor:[UIColor whiteColor]];
[self.teamName setBackgroundColor:[UIColor clearColor]];
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = self.teamName.bounds;
gradientLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor whiteColor]CGColor], (id)[[UIColor blackColor]CGColor], nil];
[self.view.layer insertSublayer:gradientLayer atIndex:0];
这篇关于如何在 iPhone 中为 UILabel 的背景设置渐变颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文