objective c - Drawing gradient on UIView not working with iOS 9 -
i'm trying draw gradient on background view of view controller ios 9 but, don't know why, isn't working
here method, called viewdidload
- (void)drawgradient { cagradientlayer *gradient = [cagradientlayer layer]; gradient.frame = self.view.bounds; gradient.colors = @[[uicolor greencolor], [uicolor redcolor]]; gradient.locations = @[@0.0, @1.0]; [self.view.layer insertsublayer:gradient atindex:0]; }
but nothing happens , gradient doesn't appear. i'm doing wrong?
thanks larme's comment, figured out mistake.
instead of
gradient.colors = @[[uicolor greencolor], [uicolor redcolor]];
the right is
gradient.colors = @[(id)[uicolor greencolor].cgcolor, (id)[uicolor redcolor].cgcolor];
because gradient.colors
expects nsarray
of cgcolorref
. (id)
cast needed in order create nsarray
.
Comments
Post a Comment