gpt4 book ai didi

uilabel - 如何在iPhone中为UILabel的背景设置渐变色

转载 作者:行者123 更新时间:2023-12-02 07:36:56 28 4
gpt4 key购买 nike

我正在使用以下代码将渐变颜色设置为标签的背景,但没有效果我做错了什么?代码在这里:

    [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 插入主视图时它工作正常。

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

关于uilabel - 如何在iPhone中为UILabel的背景设置渐变色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15382366/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com