Tôi đang cố gắng tạo UIView
s theo chương trình. Làm thế nào để có được một UIButton
với một chức năng hành động trong Swift?Cách tạo UIButton theo lập trình
Các mã sau đây không nhận được bất kỳ hành động:
let btn: UIButton = UIButton(frame: CGRectMake(100, 400, 100, 50))
btn.backgroundColor = UIColor.greenColor()
btn.setTitle("Click Me", forState: UIControlState.Normal)
btn.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(buttonPuzzle)
Chức năng chọn sau đây là:
func buttonAction(sender: UIButton!) {
var btnsendtag: UIButton = sender
}
Cảm ơn Nó làm việc với tôi –
Nếu == sender.tag 1 {...} –