0

I'm using the SCLAlertView https://github.com/dogo/SCLAlertView. Adding a text field. Any idea how I can format the text field? Would like to format, the added text field for a phone number.

thx in advance

Jon
  • 1,608
  • 7
  • 25
  • 38

1 Answers1

1

Set the NSAttributedString property of the text field. You can add the customTextField into the SCLAlertView. That way, you should be able to format the text in the textBox. I think you might not need to set all the attributes of customTextField as I am doing below to achieve your goal.

    let alert = SCLAlertView(newWindow: ())
    let customTextField = UITextField()
    customTextField.attributedText = NSAttributedString(string: "Hello", attributes: [NSAttributedStringKey.foregroundColor : UIColor.red ])
    customTextField.contentMode = .left
    customTextField.textAlignment = .left
    customTextField.frame.size = CGSize(width: 0.0, height: 40.0)
    customTextField.borderStyle = .roundedRect
    alert?.addCustomTextField(customTextField)
    alert?.addTextField("Hello")

    alert?.addButton("Show Name") {
        print("text value: ")
        print(customTextField.text)
    }

    alert?.showEdit("Edit View", subTitle: "This alert view shows a text box", closeButtonTitle: "Done", duration: 0.0)

enter image description here

Awais
  • 428
  • 5
  • 13
  • I see that for TITLE and SUBTITLE, how do I format or mask a TextField [alert addTextField:@"Enter your Phone Number"]; – Jon Aug 25 '18 at 18:42
  • 1
    I have updated my answer. it is in swift, but I hope you get the idea of the solution. – Awais Aug 25 '18 at 19:55
  • thx.. but how do I format it when they type '3015551212' as 301-555-1212 or as (301) 555-1212 – Jon Aug 26 '18 at 02:46
  • 1
    https://stackoverflow.com/questions/1246439/uitextfield-for-phone-number – Awais Aug 26 '18 at 17:32
  • You can take a look at above link to learn how to format phone number. – Awais Aug 26 '18 at 17:33
  • How do you wire up ChangeCharactersinRange to the customTextfield? – Jon Aug 27 '18 at 16:08
  • Trying this in Obj C - where is alert?.addCustomTextField(customTextField), I don't see that method – Jon Aug 28 '18 at 00:17