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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -