我已創建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