UIButton in code

后端 未结 1 1105
失恋的感觉
失恋的感觉 2021-01-29 14:34

I need to add a gesture (move, rotate, scale) to a UIButton. I created the button in code, but I don\'t know how to use it. If the button is touched I want to mov

相关标签:
1条回答
  • 2021-01-29 14:48

    I need to add a gesture (move, rotate, scale) to a UIButton.

    I'm not sure I understand what you mean about adding a gesture. Right now, your buttons aren't set up to do anything at all.

    I created the button in code, but I don't know how to use it.

    You need to add a target and action to your button. When a button is tapped, it sends an action message to some other object, which is its target. To set up a button, you need to add a target and action using the -addTarget:action:forControlEvents: method inherited from UIControl. If you want the button to send a move message to the same object that's creating the button, you'd change your addButton method to include this:

    [buttonImage1 addTarget:self action:@selector(move) forControlEvents:UIControlEventTouchUpInside];
    
    0 讨论(0)
提交回复
热议问题