[英]swift Make UIButtons input text into a textbox
我想知道是否可以在按下時使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)
在選擇器方法中使用addTarget添加到按鈕中
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"
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.