xcode - How to set the cagradientcolor to the uibutton cashapelayer objective c.I want to fill colour to different shaped button -


i want add colour uibutton cashape layer.is possible according reference in url gradient color effect on cashapelayer.. can add colour uibutton cashape layer.i can see colour button stroke want gradient colour button cashape layer.please in setting colour uibutton cashape layer.the code is

 -(void)changecolour:(id)sender {  @try{ if(m_cobjbuttonptr1.layer.sublayers.count > 0){for(calayer *layer in m_cobjbuttonptr1.layer.sublayers){if([layer iskindofclass:[cashapelayer class]])              [layer removefromsuperlayer];}}if (m_cobjbuttonptr2.layer.sublayers.count > 0){         for(calayer *layer in m_cobjbuttonptr2.layer.sublayers){if([layer iskindofclass:[cashapelayer class]])[layer removefromsuperlayer];}}if(m_cobjbuttonptr3.layer.sublayers.count > 0){for(calayer *layer in m_cobjbuttonptr3.layer.sublayers){if([layer iskindofclass:[cashapelayer class]])                [layer removefromsuperlayer];}}if (m_cobjbuttonptr4.layer.sublayers.count > 0){            for(calayer *layer in m_cobjbuttonptr4.layer.sublayers){if([layer iskindofclass:[cashapelayer class]])[layer removefromsuperlayer];}}if(m_cobjbuttonptr5.layer.sublayers.count > 0){           for(calayer *layer in m_cobjbuttonptr5.layer.sublayers){if([layer iskindofclass:[cashapelayer class]])[layer removefromsuperlayer];}}}@catch (nsexception *exception){}     uibutton *tempbutton =(uibutton *)sender;     uibezierpath *apath = [uibezierpath bezierpath];     [apath movetopoint:cgpointmake(0.0, 0.0)];     [apath addlinetopoint:cgpointmake(0.0, 35.0)];     [apath movetopoint:cgpointmake(0.0, 35.0)];     [apath addlinetopoint:cgpointmake(80.0, 55.0)];     [apath movetopoint:cgpointmake(80.0, 55.0)];     [apath addlinetopoint:cgpointmake(180.0, 35.0)];     [apath movetopoint:cgpointmake(180.0, 35.0)];     [apath addlinetopoint:cgpointmake(180.0, 0.0)];     [apath movetopoint:cgpointmake(180.0, 0.0)];     [apath addlinetopoint:cgpointmake(0.0, 0.0)];     [apath closepath];     cashapelayer *shapelayer = [cashapelayer layer];         if(tempbutton.tag == 1)             shapelayer.frame = m_cobjbuttonptr1.bounds;         if(tempbutton.tag == 2)             shapelayer.frame = m_cobjbuttonptr2.bounds;         if(tempbutton.tag == 3)             shapelayer.frame = m_cobjbuttonptr3.bounds;         if(tempbutton.tag == 4)             shapelayer.frame = m_cobjbuttonptr4.bounds;         if(tempbutton.tag == 5)             shapelayer.frame = m_cobjbuttonptr5.bounds;     shapelayer.path = apath.cgpath;     [shapelayer setstrokecolor:[[uicolor redcolor] cgcolor]];     shapelayer.fillcolor = [[uicolor redcolor] cgcolor];     shapelayer.linewidth = 2;     cagradientlayer *gradientlayer = [cagradientlayer layer];     if(tempbutton.tag == 1)         gradientlayer.frame = m_cobjbuttonptr1.bounds;     if(tempbutton.tag == 2)         gradientlayer.frame = m_cobjbuttonptr2.bounds;     if(tempbutton.tag == 3)         gradientlayer.frame = m_cobjbuttonptr3.bounds;     if(tempbutton.tag == 4)         gradientlayer.frame = m_cobjbuttonptr4.bounds;     if(tempbutton.tag == 5)         gradientlayer.frame = m_cobjbuttonptr5.bounds;     gradientlayer.colors = [nsarray arraywithobjects:      (id)[uicolor colorwithred:0.98f green:0.31f blue:0.46f alpha:0.0].cgcolor,      (id)[uicolor colorwithred:0.98f green:0.31f blue:0.14f alpha:0.0].cgcolor,nil];     gradientlayer.locations = [nsarray arraywithobjects:                                [nsnumber numberwithfloat:0.0f],                                [nsnumber numberwithfloat:1.0f],                                nil];     if(tempbutton.tag == 1){         cagradientlayer *gradientlayer = [cagradientlayer layer];         gradientlayer.startpoint = cgpointmake(0.5,1.0);         gradientlayer.endpoint = cgpointmake(0.5,0.0);         gradientlayer.frame = cgrectmake(0, 0, shapelayer.frame.size.width,                      shapelayer.frame.size.height);         nsmutablearray *colors = [nsmutablearray array];         (int = 0; < 10; i++) {              [colors addobject:(id)[[uicolor colorwithhue:(0.1 * i) saturation:1       brightness:.8 alpha:1] cgcolor]];         }         gradientlayer.colors = colors;         [gradientlayer setmask:shapelayer];         [shapelayer setfillrule:kcafillruleevenodd];         [shapelayer setfillcolor:[[uicolor orangecolor] cgcolor]];          [m_cobjbuttonptr1.layer addsublayer:shapelayer];     }     if(tempbutton.tag == 2){          cagradientlayer *gradientlayer = [cagradientlayer layer];         gradientlayer.startpoint = cgpointmake(0.5,1.0);         gradientlayer.endpoint = cgpointmake(0.5,0.0);         gradientlayer.frame = cgrectmake(0, 0, m_cobjbuttonptr2.layer.frame.size.width, m_cobjbuttonptr2.layer.frame.size.height);         nsmutablearray *colors = [nsmutablearray array];         (int = 0; < 10; i++) {             [colors addobject:(id)[[uicolor colorwithhue:(0.1 * i) saturation:1 brightness:.8 alpha:1] cgcolor]];         }         gradientlayer.colors = [nsarray arraywithobjects:             (id)[uicolor colorwithred:0.98f green:0.31f blue:0.46f alpha:0.0].cgcolor,             (id)[uicolor colorwithred:0.98f green:0.31f blue:0.14f alpha:0.0].cgcolor,             nil];         [gradientlayer setmask:shapelayer];         [m_cobjbuttonptr2.layer addsublayer:shapelayer];     }     if(tempbutton.tag == 3){         cagradientlayer *gradientlayer = [cagradientlayer layer];         gradientlayer.startpoint = cgpointmake(0.5,1.0);         gradientlayer.endpoint = cgpointmake(0.5,0.0);         gradientlayer.frame = cgrectmake(0, 0, m_cobjbuttonptr3.layer.frame.size.width, m_cobjbuttonptr3.layer.frame.size.height);         nsmutablearray *colors = [nsmutablearray array];         (int = 0; < 10; i++) {             [colors addobject:(id)[[uicolor colorwithhue:(0.1 * i) saturation:1 brightness:.8 alpha:1] cgcolor]];         }         gradientlayer.colors = colors;         [gradientlayer setmask:shapelayer];         [m_cobjbuttonptr3.layer addsublayer:shapelayer];     }     if(tempbutton.tag == 4){         cagradientlayer *gradientlayer = [cagradientlayer layer];         gradientlayer.startpoint = cgpointmake(0.5,1.0);         gradientlayer.endpoint = cgpointmake(0.5,0.0);         gradientlayer.frame = cgrectmake(0, 0, m_cobjbuttonptr4.layer.frame.size.width, m_cobjbuttonptr4.layer.frame.size.height);         nsmutablearray *colors = [nsmutablearray array];         (int = 0; < 10; i++) {             [colors addobject:(id)[[uicolor colorwithhue:(0.1 * i) saturation:1 brightness:.8 alpha:1] cgcolor]];         }         gradientlayer.colors = colors;         [gradientlayer setmask:shapelayer];         [m_cobjbuttonptr4.layer addsublayer:shapelayer];     }     if(tempbutton.tag == 5){         cagradientlayer *gradientlayer = [cagradientlayer layer];         gradientlayer.startpoint = cgpointmake(0.5,1.0);         gradientlayer.endpoint = cgpointmake(0.5,0.0);         gradientlayer.frame = cgrectmake(0, 0, m_cobjbuttonptr5.layer.frame.size.width, m_cobjbuttonptr5.layer.frame.size.height);         nsmutablearray *colors = [nsmutablearray array];         (int = 0; < 10; i++) {             [colors addobject:(id)[[uicolor colorwithhue:(0.1 * i) saturation:1 brightness:.8 alpha:1] cgcolor]];         }         gradientlayer.colors = colors;         [gradientlayer setmask:shapelayer];         [m_cobjbuttonptr5.layer addsublayer:shapelayer];     }  } 


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -