我有一種方法可以創建一個自定義UIButton,使我可以使用QuartzCore更改按鈕的顏色。但按鈕在被觸摸時不會突出顯示。自定義UIButton觸摸時不突出
- (UIButton *)makeHeaderButton {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIFont *textFont = [UIFont boldSystemFontOfSize:12];
UIColor *textColor = [UIColor colorWithRed:80/255.0 green:109/255.0 blue:145/255.0 alpha:1.0];
UIColor *backgroundColor = [UIColor colorWithRed:250/255.0 green:250/255.0 blue:250/255.0 alpha:1.0];
[button setTitleColor:textColor forState:UIControlStateNormal];
button.titleLabel.font = textFont;
button.autoresizesSubviews = YES;
button.layer.cornerRadius = 8;
button.layer.borderWidth = 1;
// next 2 properties set using QuartzCore class, no other way to set button colors
button.layer.borderColor = [UIColor grayColor].CGColor;
button.layer.backgroundColor = backgroundColor.CGColor;
button.clipsToBounds = YES;
return button;
}
如何讓這些按鈕像普通的圓形按鈕一樣突出顯示?
這似乎只是使標題淡出和進入。我希望當按鈕被觸摸時,按鈕背景會閃爍爲藍色。 – Bob
@Bob你總是可以設置手動高亮顯示。例如:註冊一個事件'onTouchDown'(或任何它),然後在實現中做一些事情''button.layer.backgroundColor = [UIColor BlueColor];'然後'onTouchUp'改變顏色回到您的設置 – Garrett
哇,這變得越來越複雜。我想要做的就是製作一個具有自定義背景色的RoundRect按鈕。當然有一個更簡單的方法來做到這一點。 – Bob