我想知道是否可以在按下时将UIButton输入文本输入文本框
override func viewDidLoad() {
super.viewDidLoad()
var textBox = UITextField(frame: CGRectMake(x, y, w, h))
textBox.borderStyle = UITextBorderStyle.Line
self.view.addSubview(textBox)
var button = UIButton(frame: CGRectMake(x, y, w, h))
button.backgroundColor = UIColor.blueColor()
self.view.addSubview(button)
}
有没有办法让var按钮输入文本到文本框(var textBox)
答案 0 :(得分:0)
var textBox = UITextField!
var button = UIButton!
override func viewDidLoad() {
super.viewDidLoad()
textBox = UITextField(frame: CGRectMake(x, y, w, h))
textBox.borderStyle = UITextBorderStyle.Line
self.view.addSubview(textBox)
button = UIButton(frame: CGRectMake(x, y, w, h))
button.backgroundColor = UIColor.blueColor()
button.addTarget(self,
action:#selector(buttonTapped),
forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button)
}
func buttonTapped(object:AnyObject) {
textBox?.text = "your text"
}