1
我想在視圖上設置漸變背景,但我的代碼如下使UIView顯示爲純黑色。如果我將whiteColor更改爲greenColor,漸變顯示正確。將圖層的backgroundColor更改爲greenColor使視圖顯示爲純綠色。CAGradientLayer顯示爲純色
我的猜測是我正在處理某種透明度問題,但我無法解決這個問題。
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.colors = [NSArray arrayWithObjects:
(id)[[UIColor whiteColor] CGColor],
(id)[[UIColor blackColor] CGColor], nil];
gradientLayer.frame = CGRectMake(0, 0, 1, someView.frame.size.height);
UIGraphicsBeginImageContext(CGSizeMake(1, someView.frame.size.height));
[gradientLayer renderInContext: UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
someView.backgroundColor = [UIColor colorWithPatternImage: image];