【发布时间】:2024-01-24 12:25:01
【问题描述】:
我需要知道我做错了什么。我从字面上复制并粘贴到我的代码中,渐变没有显示。
#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
它只是显示一个白屏。谁能帮我找出问题所在。因为它现在真的让我很烦。
【问题讨论】:
标签: ios objective-c core-graphics core-animation cagradientlayer