一开始,我想通过自我设计功能创建每个textField:
func creatTextField(x x0:Int,y y0: Int,w w0: Int,h h0: Int) -> UITextField{
let x = CGFloat(x0)
let y = CGFloat(y0)
let w = CGFloat(w0)
let h = CGFloat(h0)
let frame = CGRectMake(0, 0, w, h)
let center = CGPointMake(x/2, y/2)
let tf = UITextField(frame: frame)
tf.center = center
view.addSubview(tf)
return tf
}
并且在viewDidLoad()中,我只想添加一个新的TextField:
override func viewDidLoad() {
super.viewDidLoad()
TextField = creatTextField(x: 50, y: 50, w: 100, h: 30)
}
当我运行程序时没有任何改变
我正在考虑我是否遗漏了诸如CONSTRAIN之类的内容,或者我应该使用STACK VIEW来正确呈现这些textField?
我希望有人可以帮助我! :d
b.t.w。 因为它只是一个测试,我只需添加一个textField。但我应该是 2D-Array< UITextField>
答案 0 :(得分:2)
只需将此行添加到您的代码中:
tf.borderStyle = UITextBorderStyle.RoundedRect
最终的代码是:
func creatTextField(x x0:Int,y y0: Int,w w0: Int,h h0: Int) -> UITextField{
let x = CGFloat(x0)
let y = CGFloat(y0)
let w = CGFloat(w0)
let h = CGFloat(h0)
let frame = CGRectMake(0, 0, w, h)
let center = CGPointMake(x/2, y/2)
let tf = UITextField(frame: frame)
tf.center = center
tf.borderStyle = UITextBorderStyle.RoundedRect
view.addSubview(tf)
return tf
}