我在. _ UIViewController
在每个自定义视图中,我都使用 CAShapeLayer 创建了形状。
这些图层还包含渐变色。现在我想将渐变颜色设置为自定义视图。当我试图这样做时,它正在崩溃。对于第一个视图,这里是代码:
//first component
self.aTimeScaleMonthView = [[TimeScaleView alloc] initWithFrame:CGRectMake(ORIGIN_X, frame.origin.y, frame.size.width-(2*ORIGIN_X), HEIGHT_OF_COMPONENT1) withStartDate:startDate endDate:endDate];
self.aTimeScaleMonthView.modeOfScale = A3TimeScaleMonth;
self.aTimeScaleMonthView.layer.borderColor = [UIColor blackColor].CGColor;
self.aTimeScaleMonthView.layer.borderWidth = BORDER_WIDTH_BOX;
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.aTimeScaleMonthView.bounds;
gradient.colors = [NSArray arrayWithObjects:[UIColor colorWithRed:0.66 green:0.29 blue:0.22 alpha:1.0], [UIColor colorWithRed:0.62 green:0.51 blue:0.314 alpha:1.0], nil];
[self.aTimeScaleMonthView.layer insertSublayer:gradient atIndex:0];
[self addSubview: self.aTimeScaleMonthView];
请帮我。