我已创建3个自定义视图在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];
请帮助我。
很酷...其工作正常 – user007