【问题标题】:Objective-c , Setting two views of gradient , but only one correctObjective-c ,设置两个渐变视图,但只有一个正确
【发布时间】:2023-04-01 19:25:02
【问题描述】:

我有一个问题。有没有人可以给我一些提示?

我在情节提要中设置了两个视图。

我构建了一个 AbstractViewController,这个类是 UIViewController 的扩展类。

然后我的 IndexViewController 扩展了 AbstractViewController。

我的渐变代码是写在 AbstractViewController 中的。

代码如下。

-(UIView *) setGradientView:(UIView *) gradientView initColor:(UIColor*) initColor     andFinshColor:(UIColor*)finshColor
{

    {
        initColor =[UIColor whiteColor] ;

    }

    if( finshColor == nil )
    {
        finshColor = [UIColor colorWithRed:230.0f/255.0f green:230.0f/255.0f     blue:230.0f/255.0f alpha:1.0f];
    }

    CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.frame = gradientView.bounds;
    gradient.colors = [NSArray arrayWithObjects:(id)[initColor CGColor],(id)[finshColor     CGColor],nil];
    [gradientView.layer insertSublayer:gradient atIndex:0];
    return gradientView;

}

然后我在 IndexViewController 中调用渐变。 我在 viewDidLoad 中写。

代码如下:

[self setGradientView:_bgView initColor:nil andFinshColor:nil];
[self setGradientView:_bottomView initColor:[UIColor colorWithRed:10.0f/255.0f     green:10.0f/255.0f blue:1.0f/255.0f alpha:1.0f]
        andFinshColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f     blue:10.0f/255.0f alpha:1.0f]];

结果只有 _bgView 有改变颜色。 _bottomView 没有改变。

我对 _bottomView 没有改变颜色感到困惑。

有人知道吗?

谢谢~

【问题讨论】:

  • 试试这个。 [self setGradientView:_bottomView initColor:nil andFinshColor:nil];
  • 但我想设置其他颜色,而不是使用 nil。 @@
  • 我知道,这是一个测试,如果成功,说明错误是由颜色引起的。
  • 我尝试更改其他颜色代码。两种观点都是正确的。非常感谢!!
  • 如果您找到了解决办法,请写下来并接受。 :)

标签: ios objective-c uiviewcontroller gradient


【解决方案1】:

我找到了解决方案。代码没有问题,我没有设置 _bottomView 引用网点。 = ="谢谢你,@KudoCC

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-24
    相关资源
    最近更新 更多