swift 使 UIButtons 在文本框中输入文本
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"
}
我想知道是否可以在按下时将 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"
}