給UIButton設(shè)置漸變色
- (void)setLoginBtnLayerColor {
CAGradientLayer *gl = [CAGradientLayer layer];
gl.frame = CGRectMake(0, 0, self.loginBtn.frame.size.width, self.loginBtn.frame.size.height);
gl.startPoint = CGPointMake(0, 0.5);
gl.endPoint = CGPointMake(1, 0.5);
gl.colors = @[(__bridge id)[UIColor colorWithRed:61/255.0 green:126/255.0 blue:255/255.0 alpha:1.0].CGColor,(__bridge id)[UIColor colorWithRed:64/255.0 green:211/255.0 blue:253/255.0 alpha:1.0].CGColor];
gl.locations = @[@(0),@(1.0f)];
gl.cornerRadius = 22;
[self.loginBtn.layer insertSublayer:gl atIndex:0];
}
效果如圖所示: