Objective C - Faded Gradient on left/right sides of UICollectionView -


i have horizontal-scrolling uicollectionview within main view of view controller (grey uiview, wood uicollectionview):

i want add fixed faded gradients on far left & far right sies of uicollectionview scrolls appear vanish user scrolls. how go doing this? involve use of cagradientlayer? grateful can give me!

i managed figure out using 1 mask layer this tutorial @ cocoanetics. here's did:

@interface scalesviewcontroller : uiviewcontroller {     cagradientlayer *masklayer; } @end 

then in .m, placed in following:

- (void)viewdidappear:(bool)animated {      [super viewwillappear: animated];      if (!masklayer)     {         masklayer = [cagradientlayer layer];          cgcolorref outercolor = [[uicolor colorwithwhite:0.0 alpha:1.0] cgcolor];         cgcolorref innercolor = [[uicolor colorwithwhite:0.0 alpha:0.0] cgcolor];          masklayer.colors = [nsarray arraywithobjects:                            (__bridge id)outercolor,                            (__bridge id)innercolor,                            (__bridge id)innercolor,                            (__bridge id)outercolor, nil];          masklayer.locations = [nsarray arraywithobjects:                               [nsnumber numberwithfloat:0.0],                               [nsnumber numberwithfloat:0.125],                               [nsnumber numberwithfloat:0.875],                               [nsnumber numberwithfloat:1.0], nil];          [masklayer setstartpoint:cgpointmake(0, 0.5)];         [masklayer setendpoint:cgpointmake(1, 0.5)];          masklayer.bounds = self.maincollectionview.bounds;         masklayer.anchorpoint = cgpointzero;          [self.maincollectionview.layer insertsublayer: masklayer atindex: 0];     } } 

this creates nice "fade black" effect on both sides of collection view. more colors can added locations & color properties refine gradient blend. start/endpoints determine direction , location of gradient.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -