title: Set Selected State of CAGradient UIButton in iOS
body: <p>Hi I have made a custom button in code using corner radius CAGradientLayer and border colour in one of my view controllers like the below:</p>
  
  <pre><code>phoneButton = [CustomButton buttonWithType:UIButtonTypeCustom];
  phoneButton.frame = CGRectMake(6, 363, 99, 48);
  phoneButton.titleLabel.font = [UIFont fontWithName:@"Futura-Medium" size:14];
  phoneButton.titleLabel.shadowColor = [UIColor colorWithWhite:0.0 alpha:1.0];
  phoneButton.titleLabel.shadowOffset = CGSizeMake(0, 1);
  [phoneButton setTitle:@"Phone" forState:UIControlStateNormal];
  [phoneButton addTarget:self action:@selector(phone) forControlEvents:UIControlEventTouchUpInside];
  
  gradient = [CAGradientLayer layer];
  gradient.frame = phoneButton.bounds;
  gradient.cornerRadius = 8;
  gradient.borderColor = [[UIColor whiteColor]CGColor];
  gradient.borderWidth = 2.0;
  gradient.colors = [NSArray arrayWithObjects:(id)[[sharedManager cellGradientEnd] CGColor], (id)[[sharedManager cellGradientStart] CGColor], nil];
  [phoneButton.layer insertSublayer:gradient atIndex:0];
  [self.view addSubview:phoneButton];
  </code></pre>
  
  <p>Now I would like to set the selected/highlighted color of the button on selection. How do I do this. I read make a UIbutton subclass and override setSelected but I dont have a clue how to do it. Here is customButton subclass.m</p>
  
  <pre><code>#import "CustomButton.h"
  
  @implementation CustomButton
  @synthesize sharedManager;
  
  - (id)initWithFrame:(CGRect)frame
  {
  self = [super initWithFrame:frame];
  if (self) {
      // Initialization code
      sharedManager = [[MySingleton alloc]init];
  
      }
  return self;
  }
  
  
  -(void) setHighlighted:(BOOL)highlighted {
  
  if(highlighted) {
      NSLog(@"Highlighted");
  
  
  } else {
      NSLog(@"Not Highlighted");
  
  }
  
  [super setHighlighted:highlighted];
  }
  
  -(void) setSelected:(BOOL)selected {
  
  if(selected) {
      NSLog(@"Selected");
  
  } else {
      NSLog(@"Not Selected");
  }
  [super setSelected:selected];
  }
  
  
  
  @end
  </code></pre>
  
  <p>Or just dim the button on selection would be good? I should add that the button is not in a Xib.</p>