0

I want to customise all the textFields at once via AppDelegate , I had tested the customisation working on individual ViewControllers but when I add the customisation through AppDelegate then it does not appears. Please guide me for what have I missed :

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    UITextField.appearance().layer.borderWidth = 2
    UITextField.appearance().layer.borderColor = UIColor(red:0.094 , green:0.737 ,  blue:0.612 ,  alpha:1).CGColor
           return true
}
ziad.mediaphone
  • 21
  • 1
  • 10

2 Answers2

1

I found the solution , thanx to @nannav. Rather than customising the TextField in AppDelegate, we should create a new class like :

class MyCustomTextField: UITextField {
required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    self.layer.borderWidth = 2
    self.layer.borderColor = UIColor(red:0.094 , green:0.737 ,  blue:0.612 ,  alpha:1).CGColor
}

}

later in storyBoard we have to assign MyCustomTextField in customClass to the Textfields we wanted to customise

ziad.mediaphone
  • 21
  • 1
  • 10
1

UITextField is not tagged with UI_APPEARANCE_SELECTOR so this is the reason why it does not work like UITextField.appearance()....

For more info, look at What properties can I set via an UIAppearance proxy?

Community
  • 1
  • 1
Patrik Vaberer
  • 646
  • 6
  • 15