如何以编程方式在视图中心打印多个文本字段?

时间:2017-04-29 11:35:30

标签: iphone swift3 uitextfield uitextfielddelegate

我正在尝试在视图中间打印多个textField,但我不能。我想点击textfield.textfield应该在视图的中间,字体大小将作为文本字段大小管理。

这是我的代码:

for i in 0..<characters.count
{
    let textField : UITextField = UITextField(frame : CGRect(x:(charWidth/13) * CGFloat(i) + CenterX, y:0, width:charWidth/14, height:charWidth/12))
    textField.font =  UIFont(name: "Noteworthy", size: 50)
    textField.text = "\(characters[i])".lowercased()

    textField.textAlignment = .center
    textField.resizeText()
    textField.adjustsFontSizeToFitWidth = true
    textField.minimumFontSize = 1.0
    textField.delegate = self

    textField.autocapitalizationType = .none
    //textView.font = UIFont
}

1 个答案:

答案 0 :(得分:0)

尝试简单地对textField使用不同的方法,首先你将textField不是textView。所有textFields都有自己的出口。

How do I check when a UITextField changes?

https://developer.apple.com/reference/uikit/uitextfielddelegate

以下是Swift 3可点击textField的代码:

myTextField.addTarget(self, action: #selector(myTargetFunction), for: .touchDown)
This is the function:

func myTargetFunction() {
    print("It works!")
}