Ios 为什么我的CAGradientLayer没有显示?

Ios 为什么我的CAGradientLayer没有显示?,ios,objective-c,core-graphics,core-animation,cagradientlayer,Ios,Objective C,Core Graphics,Core Animation,Cagradientlayer,我需要知道我做错了什么。我真的复制并粘贴到我的代码和梯度没有显示这一点 #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIView *gradient_view = [[UIView alloc]initWithFrame:self.view.bo

我需要知道我做错了什么。我真的复制并粘贴到我的代码和梯度没有显示这一点

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];


    UIView *gradient_view = [[UIView alloc]initWithFrame:self.view.bounds];
    CAGradientLayer *gradient_layer = [CAGradientLayer layer];
    [gradient_layer setFrame:gradient_view.bounds];

    gradient_layer.startPoint = CGPointMake(0, 0);
    gradient_layer.endPoint = CGPointMake(0, 1);

    UIColor *top_color = [UIColor redColor];
    UIColor *bottom_color = [UIColor blueColor];
    [gradient_layer setColors:@[top_color,bottom_color]];
    [gradient_view.layer addSublayer:gradient_layer];
    [self.view addSubview:gradient_view];


}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

它只显示一个白色屏幕。谁能帮我弄清楚问题是什么。因为它现在真的很烦我。

你可能会踢自己:)

渐变层需要CGColorRef,而不是UIColor:

CGColorRef topRef = [UIColor redColor].CGColor;
CGColorRef botRef = [UIColor blueColor].CGColor;

[gradient_layer setColors:@[(__bridge id)topRef, (__bridge id)botRef]];