[英]a lot of button add same addTarget(_:action:for:) method
I'm working on a calculate app. 我正在开发一个计算应用程序。 and has ton of button which I store in a big stackView (created in SB and no outlet).
并有很多按钮,我将它们存储在一个大的stackView中(在SB中创建,没有插座)。 each button cast some shadow (also set in SB attribute).
每个按钮都会投射一些阴影(也在SB属性中设置)。 I want to get rid of shadow when button was pressed.
我想摆脱按下按钮时的阴影。 either tapGestureRecognizer or target action could only effect one UIButton.
tapGestureRecognizer或目标动作只能影响一个UIButton。 any convenience way to acheive
任何方便的方法
PS I mean when button .touchupinside or tapGestureRecognizer .end .start when finger move button should still cast the shadow PS我的意思是当按钮.touchupinside或tapGestureRecognizer .end .start。当手指移动按钮仍应投射阴影时
help appreciated 帮助赞赏
UIButton will highlighted on click, so check button setting Change the title color in highlight state config to same as default state Or you can set: UIButton会在单击时突出显示,因此请选中按钮设置将突出显示状态配置中的标题颜色更改为默认状态,或者您可以设置:
[button setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
If you want to control Highlighted by code, you can disable normal highlighted by subclass Button and disable in touchesBegin: 如果要控制“代码突出显示”,则可以禁用子类Button突出显示的普通文本,并在touchesBegin中禁用:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
if (self.state == UIControlStateHighlighted) {
[self setHighlighted:NO];
}
}
You can assign the same IBAction to multiple buttons, so that the same method is called for all of them 您可以将相同的IBAction分配给多个按钮,以便为所有按钮调用相同的方法
func buttonDidTouch(sender:UIButton) {}
If now you want to identify which exactly button is being called, you can use the UIButton.tag property to identify it. 现在,如果您想确定正在调用的确切按钮,则可以使用UIButton.tag属性进行标识。 The tag can be set in the SB for each button.
可以在SB中为每个按钮设置标签。
There are so many way to achieve the goal but I'm going with below. 有很多方法可以实现目标,但我将在下面进行介绍。
Just give my logic. 请给出我的逻辑。 Take one temporary optional variable of
UIButton
取一个
UIButton
临时可选变量
Ex. 防爆。
var myTemButton: UIButton()?
In the button action method 在按钮动作方式
@IBAction func myButtonActionFunc(_ sender: UIButton) {
if myTemButton == nil {
myTemButton = sender
}
else {
// Use "myTemButton" and write here code for remove shadow Or other stuff that you want.
}
// use "sender" and write code here for apply shadow of button or other stuff that you want.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.