草庐IT

configureButton

全部标签

ios - 如何动态地向 UIButton 添加 Action

我注意到我有很多功能可以在我的一个ViewController中动态添加按钮,这显然违反了DRY原则。为了解决这个问题,我写了一个命中一切的configureButton函数:funcconfigureButton(button:UIButton,action:String,title:String,pos:[CGFloat]){button.addTarget(self,action:action,forControlEvents:UIControlEvents.TouchUpInside)//^throwsanerror//button.addTarget(self,action: