0

I didn't find an answer that solved my problems or that was explained in an easy way. So please don't give me any other stack overflow links because I realy read them and couldn't solve my problem. I also looked up in the documentation. Thanks for helping me out.

Problem1: Im building an iOS app with SWIFT and don't use storyboards for the user interfaces. I created a LoginController with the UItextfield userName where a new user can enter his userName (see below : userNameTextField ). I changed the placeholder text to the String "Name".

Question1: How can I change the placeholder font and textsize. I want to have a bold placeholder text.

let userNameTextField: UITextField = {
    let tf = UITextField()
    tf.placeholder = "Name"
    tf.translatesAutoresizingMaskIntoConstraints = false

    return tf

}()

Problem2:

Usernames must be at least five characters long before the registration can work. How can I guarantee this in my code. A kind of notification would be cool like Sorry you need at least 5 characters. Can you please give me just a short example for one UiTextField Object ?

Thanks

Morphley
  • 121
  • 1
  • 7
  • 1
    Problem 2: See http://stackoverflow.com/questions/7329631/how-to-require-a-minimum-text-length-in-uitextfield-before-enabling-keyboard-ret – kennytm Mar 11 '17 at 20:39
  • Problem 1: Do you want to just change the placeholder font, or placeholder + text font? – kennytm Mar 11 '17 at 20:40
  • Look at the attributedPlaceholder property of a UITextField. I'm pretty sure it's what you want. – dylanthelion Mar 11 '17 at 20:42

1 Answers1

0

Problem 1:

tf.font = UIFont.boldSystemFont(ofSize: 16.0)

Problem 2:

You can check this answer out on how to create a pop up message (UIAlertView)

Community
  • 1
  • 1
Ray Tso
  • 566
  • 9
  • 17