0

I am trying to print multiple textField in middle of the view but I can't. I wanna clickable textfield.textfield should be middle of the view and font size will be manage as textfield size.

This is my code:

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
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
seggy
  • 1,176
  • 2
  • 18
  • 38

1 Answers1

0

Try simply use different method for a textField and firstly you take textField not a textView. All textFields have a its own outlets.

How do I check when a UITextField changes?

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

Here is the code for Swift 3 clickable textField:

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

func myTargetFunction() {
    print("It works!")
}
Community
  • 1
  • 1
harp
  • 123
  • 1
  • 4
  • Thanks for answer, please read my question carefully i want programmatically multiple textfield on middle of view. and yes i am using textField not textView – seggy May 01 '17 at 06:49
  • Try to follow link,i think it should also work with text: "NSAttributedString" http://stackoverflow.com/questions/24666515/how-do-i-make-an-attributed-string-using-swift – harp May 01 '17 at 07:02