我试图使用以下代码为导航栏设置渐变,但应用程序在最后一行崩溃并出现 EXC_BAD_ACCESS 错误。
UIColor* topColor = [UIColor colorWithRed:245.0/255 green:245.0/255 blue:245.0/255 alpha:1.0];
UIColor* bottomColor = [UIColor colorWithRed:200.0/255 green:200.0/255 blue:200.0/255 alpha:1.0];
CAGradientLayer* navBarGradientLayer = [CAGradientLayer layer];
[navBarGradientLayer setFrame:CGRectMake(0, 0, self.navigationController.navigationBar.bounds.size.width, self.navigationController.navigationBar.bounds.size.height)];
NSArray* gradientColors = @[topColor, bottomColor];
navBarGradientLayer.colors = gradientColors;
[self.navigationController.navigationBar.layer insertSublayer:navBarGradientLayer atIndex:0];
我在这里做错了什么?