我正在尝试将渐变 View 添加到 iOS 应用程序的背景中。
使用 pod UIColor+uiGradients
我在 viewDidLoad
下的背景中添加了一个 GradientLayer:
- (void)viewDidLoad {
[super viewDidLoad];
UIColor *startColor = [UIColor uig_emeraldWaterStartColor];
UIColor *endColor = [UIColor uig_emeraldWaterEndColor];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.view.bounds;
gradient.startPoint = CGPointMake(0, 0);
gradient.endPoint = CGPointMake(self.view.frame.size.width, 0);
gradient.colors = @[(id)[startColor CGColor], (id)[endColor CGColor], nil];
[self.view.layer insertSublayer:gradient atIndex:0];
}
错误发生在行 gradients.colors = @[(id)[startColor CGColor], (id)[endColor CGColor], nil];
错误:
Collection element of type 'void *' is not an Objective-C object.
感谢您的帮助。
最佳答案
删除数组末尾的 nil。您不能将 nil 放入 Objective-C 数组中,在 @[]
文字中也没有必要。所以:
gradient.colors = @[(id)[startColor CGColor], (id)[endColor CGColor]];
关于objective-c - 'void *' 类型的集合元素不是 Objective-C 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26900146/