4
我想創建一個具有漸變背景的UIButton。我得到的工作很好,但按鈕不會突出顯示(默認行爲是爲了讓按鈕變暗)。如何使用漸變創建UIButton並突出顯示?
這裏是我的按鈕:
-(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;
}
我需要處理突出自己?
完美,節省了我的時間從做繁重的工作,謝謝! – Padin215
沒問題。乾杯! :) – memmons