UITextField border color

后端 未结 9 1467
一生所求
一生所求 2020-11-28 02:43

I have really great wish to set my own color to UITextField border. But so far I could find out how to change the border line style only.

I\'ve used background prope

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 03:28

    Here's a Swift implementation. You can make an extension so that it will be usable by other views if you like.

    extension UIView {
        func addBorderAndColor(color: UIColor, width: CGFloat, corner_radius: CGFloat = 0, clipsToBounds: Bool = false) {
            self.layer.borderWidth  = width
            self.layer.borderColor  = color.cgColor
            self.layer.cornerRadius = corner_radius
            self.clipsToBounds      = clipsToBounds
        }
    }
    

    Call this like: email.addBorderAndColor(color: UIColor.white, width: 0.5, corner_radius: 5, clipsToBounds: true).

提交回复
热议问题