AppDelegate中的UITextField自定义不适用于Swift [英] UITextField customization in AppDelegate not working for Swift

查看:89
本文介绍了AppDelegate中的UITextField自定义不适用于Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过AppDelegate一次自定义所有textField,我已经测试了在各个ViewController上进行的自定义,但是当我通过AppDelegate添加自定义时,它不会出现.请指导我我错过了什么:

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
}

推荐答案

我找到了@nannav的解决方案,thanx.与其在AppDelegate中自定义TextField,不如创建一个新类:

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
}

}

稍后在StoryBoard中,我们必须将customClass中的 MyCustomTextField 分配给我们要自定义的文本字段

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

这篇关于AppDelegate中的UITextField自定义不适用于Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆