ios - How to make a custom button with highlighted -


this question exact duplicate of:

i create custom button, because want gradient button. use code implement it.

 @implementation custombutton   - (id)initwithframe:(cgrect)frame {     if((self = [super initwithframe:frame])){         [self setupview];     }      //[self addobserver:self forkeypath:@"highlighted"  options:0 context:nil];     return self; }  - (void)awakefromnib {     [self setupview]; }  # pragma mark - main  - (void)setupview {     self.layer.cornerradius = 10;     self.layer.borderwidth = 1.0;     self.layer.bordercolor = [uicolor colorwithred:167.0/255.0 green:140.0/255.0 blue:98.0/255.0 alpha:0.25].cgcolor;     self.layer.shadowcolor = [uicolor blackcolor].cgcolor;     self.layer.shadowradius = 1;     [self clearhighlightview];      cagradientlayer *gradient = [cagradientlayer layer];     gradient.frame = self.layer.bounds;     gradient.cornerradius = 10;     gradient.colors = [nsarray arraywithobjects:                        (id)[uicolor colorwithwhite:1.0f alpha:0.4f].cgcolor,                        (id)[uicolor colorwithwhite:1.0f alpha:0.2f].cgcolor,                        (id)[uicolor colorwithwhite:0.75f alpha:0.2f].cgcolor,                        (id)[uicolor colorwithwhite:0.4f alpha:0.2f].cgcolor,                        (id)[uicolor colorwithwhite:1.0f alpha:0.4f].cgcolor,                         nil];    // float height = gradient.frame.size.height;     gradient.locations = [nsarray arraywithobjects:                           [nsnumber numberwithfloat:0.0f],                           [nsnumber numberwithfloat:0.5f],                           [nsnumber numberwithfloat:0.5f],                           [nsnumber numberwithfloat:0.8f],                           [nsnumber numberwithfloat:1.0f],                           nil];     [gradient setbackgroundcolor:[uicolor redcolor].cgcolor];     [self.layer insertsublayer:gradient atindex:0]; } 

now gradient has been completed. when press button , there no highlighted status on it.

i want when pressed color has been deepen. know how implement this? thanks

if subclass uibutton can override sethighlighted method. here can set different gradient on button.

- (void)sethighlighted:(bool)highlighted  {     [super sethighlighted:highlighted];  } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -