标签:events 调用 touch for style super button controls cti
直接上代码:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let btn = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: 300, height: 100))
btn.setTitle("按钮", for: UIControlState.normal)
btn.setTitleColor(UIColor.black, for: .normal)
self.view.addSubview(btn)
btn.addTarget(self, action: #selector(self.action(btn:)), for: UIControlEvents.touchUpInside)
self.p() //函数调用没毛病
}
@objc func action(btn:UIButton){ //添加了@objc修饰符,应该只有事件方法做了修饰限定
print(btn)
print("打印一下")
}
func p(){
print("调用函数")
}
}
标签:events 调用 touch for style super button controls cti
原文地址:http://www.cnblogs.com/lc901221/p/7602560.html