gpt4 book ai didi

iOS 有边框按钮点击时的行为

转载 作者:行者123 更新时间:2023-11-29 01:54:24 26 4
gpt4 key购买 nike

我的应用程序中需要一个带边框的 pre-iOS UIButton。我使用:

btn.layer.borderColor = [UIColor blackColor].CGColor;

btn.layer.borderWidth = 1.0;

btn.layer.cornerRadius = 10;

这工作正常,但点击边框不闪烁(按钮高亮状态)。有什么方法可以轻松实现吗?

最佳答案

在创建按钮时实现:

[self.botonConfigurar addTarget:self action:@selector(setBgColorForButton:) forControlEvents:UIControlEventTouchDown];
[self.botonConfigurar addTarget:self action:@selector(clearBgColorForButton:) forControlEvents:UIControlEventTouchDragExit];
[self.botonConfigurar addTarget:self action:@selector(setBgColorForButton:) forControlEvents:UIControlEventTouchDragEnter];

还有这两个函数:

-(void)setBgColorForButton:(UIButton*)sender {

[self.botonConfigurar setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.botonConfigurar.layer.backgroundColor = [UIColor colorWithRed:89/255.0 green:194/255.0 blue:237/255.0 alpha:1.0].CGColor;
}

-(void)clearBgColorForButton:(UIButton*)sender {

[self.botonConfigurar setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.botonConfigurar.layer.backgroundColor = [UIColor colorWithRed:61/255.0 green:169/255.0 blue:222/255.0 alpha:1].CGColor;

}

用这些函数中的按钮做任何你想做的事。

PD:让你的按钮成为[UIButton buttonWithType:UIButtonTypeCustom]

PD2:在clearBgColorForButton:sender中写入您的UIButton的原始参数。

关于iOS 有边框按钮点击时的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31049001/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com