title: How to Create a UIButton with Gradient and Highlighting?
body: <p>I am trying to create a UIButton with a gradient background. I got that work fine but the button does not highlight (default behavior is for the button to darken) when selected.</p>
  
  <p>here's my button:</p>
  
  <pre><code>-(UIButton *)createLoginButtonForSize:(CGSize)size {
      UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
      loginButton.translatesAutoresizingMaskIntoConstraints = FALSE;
      loginButton.layer.cornerRadius = 8;
      loginButton.titleLabel.text = @"Login";
  
      [loginButton addTarget:self action:@selector(loginCheck:) forControlEvents:UIControlEventTouchUpInside];
  
  
      [loginButton addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[loginButton(WIDTH)]"
                                                                          options:0
                                                                          metrics:@{@"WIDTH": [NSNumber numberWithFloat:size.width]}
                                                                            views:NSDictionaryOfVariableBindings(loginButton)]];
  
      [loginButton addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[loginButton(HEIGHT)]"
                                                                          options:0
                                                                          metrics:@{@"HEIGHT": [NSNumber numberWithFloat:size.height]}
                                                                            views:NSDictionaryOfVariableBindings(loginButton)]];
  
      CAGradientLayer *layer = [UIColor greenGradient];
      layer.frame = CGRectMake(0, 0, size.width, size.height);
      layer.cornerRadius = 8;
  
      [loginButton.layer insertSublayer:layer atIndex:0];
  
      return loginButton;
  }
  </code></pre>
  
  <p>Do I need to handle the highlighting myself?</p>