Ios 如何在Swift 3中更改所有文本字段边框颜色

Ios 如何在Swift 3中更改所有文本字段边框颜色,ios,swift,uitextfield,border-color,Ios,Swift,Uitextfield,Border Color,如何在Swift 3中更改所有文本字段边框颜色 我构建了一个iPad应用程序。 我的.xib文件中有很多文本字段,现在我想更改边框颜色,但要编写特定的文本字段需要很多行,所以有什么排序方法吗?添加此扩展名为项目中的所有文本字段创建边框 extension UITextField { func cornerRadius(value: CGFloat) { self.layer.cornerRadius = value self.layer.borderWidth = 1.0

如何在Swift 3中更改所有文本字段边框颜色 我构建了一个iPad应用程序。
我的.xib文件中有很多文本字段,现在我想更改边框颜色,但要编写特定的文本字段需要很多行,所以有什么排序方法吗?

添加此扩展名为项目中的所有文本字段创建边框

extension UITextField {
func cornerRadius(value: CGFloat) {
    self.layer.cornerRadius = value
    self.layer.borderWidth = 1.0
    self.layer.borderColor = UIColor.lightGray.cgColor
    self.layer.masksToBounds = true
}}
extension UITextField
{
    open override func draw(_ rect: CGRect) {
        self.layer.cornerRadius = 3.0
        self.layer.borderWidth = 1.0
        self.layer.borderColor = UIColor.lightGray.cgColor
        self.layer.masksToBounds = true
    }
}

添加此扩展为项目中的所有文本字段创建边框

extension UITextField
{
    open override func draw(_ rect: CGRect) {
        self.layer.cornerRadius = 3.0
        self.layer.borderWidth = 1.0
        self.layer.borderColor = UIColor.lightGray.cgColor
        self.layer.masksToBounds = true
    }
}

您应该创建一个新类,它是UITextField的子类,如下所示:

import UIKit

class YourTextField: UITextField {
    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!
        self.setBorderColor()
    }
    required override init(frame: CGRect) {
        super.init(frame: frame)
        self.setBorderColor()
    }
    func setBorderColor(){
        self.layer.borderColor = .red // color you want
        self.layer.borderWidth = 3
        // code which is common for all text fields
    }
}
现在打开xib选择所有文本字段。 在identity inspector中,将自定义类更改为
YourTextField

这样,即使您的项目中有1000个文本字段,也不需要为此再写一行。

您应该创建一个新类,它是UITextField的子类,如下所示:

import UIKit

class YourTextField: UITextField {
    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!
        self.setBorderColor()
    }
    required override init(frame: CGRect) {
        super.init(frame: frame)
        self.setBorderColor()
    }
    func setBorderColor(){
        self.layer.borderColor = .red // color you want
        self.layer.borderWidth = 3
        // code which is common for all text fields
    }
}
现在打开xib选择所有文本字段。 在identity inspector中,将自定义类更改为
YourTextField

这样,即使您的项目中有1000个文本字段,也无需为此再写一行。

您可以扩展textfield。使用此:-您可以扩展textfield。使用此:-调用上述方法,如:txtfield.cornerRadius(值:5.0)我想在我的应用程序中更改每个TextField borderColor超过5000+以上的TextFieldcall上述方法,如:txtfield.cornerRadius(值:5.0)我想在我的应用程序中更改每个TextField borderColor超过5000+以上的TextField如何设置颜色#99999使用此扩展名并替换此
self.layer.borderColor=UIColor.uicolorFromHex(999999,alpha:1)).cgColor
如何设置颜色#999999使用此扩展并替换此
self.layer.borderColor=UIColor.uicolorFromHex(999999,alpha:1)).cgColor