更新时间:2023-09-25 10:26:22
感谢Larme的评论,我发现了我的错误。
Thanks to Larme's comment, I figured out my mistake.
而不是
gradient.colors = @[[UIColor greenColor], [UIColor redColor]];
这是正确的
gradient.colors = @[(id)[UIColor greenColor].CGColor, (id)[UIColor redColor].CGColor];
因为 gradient.colors
需要 NSArray
CGColorRef
。为了创建 NSArray
,还需要(id)
强制转换。
Because gradient.colors
expects a NSArray
of CGColorRef
. The (id)
cast is also needed in order to create the NSArray
.