我在Swift 4中的自定义按钮addTarget
出现问题。我尝试了所有内容,但仍然有定义选择器的问题,因为结果总是错误。
有什么想法吗?
let myButton = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
myButton.center = CGPoint(x: 200, y: 400)
myButton.backgroundColor = UIColor.purple
myButton.layer.cornerRadius = 18.0
myButton.setTitle("Tap Me", for: UIControlState.normal)
myButton.setTitleColor(UIColor.white, for: UIControlState.normal)
myButton.actions(forTarget: self, forControlEvent: UIControlEvents.touchUpInside)
myButton.isHighlighted = true
self.view.addSubview(myButton)
答案 0 :(得分:0)
试试这个
componentDidMount() {
state = someArrOfObjects.reduce((a, o) => {
return Object.assign(a, {[`list_for_${o.id}`]: o.val})
}, {})
this.setState(state)
}
按钮操作方法
myButton.addTarget(self, action: #selector(self.btnClickAction(_:)), for: .touchUpInside)