Skip to content

Instantly share code, notes, and snippets.

@29satnam
Created July 19, 2017 09:40
Show Gist options
  • Save 29satnam/5e88bc9203b04b68296d23b85a14efe1 to your computer and use it in GitHub Desktop.
Save 29satnam/5e88bc9203b04b68296d23b85a14efe1 to your computer and use it in GitHub Desktop.
This is how you can set only Bottom Border to UITextField using Swift 3
class BottomBorderTF: UITextField {
var bottomBorder = UIView()
override func awakeFromNib() {
//MARK: Setup Bottom-Border
self.translatesAutoresizingMaskIntoConstraints = false
bottomBorder = UIView.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
bottomBorder.backgroundColor = UIColor.orange
bottomBorder.translatesAutoresizingMaskIntoConstraints = false
addSubview(bottomBorder)
//Mark: Setup Anchors
bottomBorder.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
bottomBorder.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
bottomBorder.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
bottomBorder.heightAnchor.constraint(equalToConstant: 1).isActive = true // Set Border-Strength
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment