Skip to content

Instantly share code, notes, and snippets.

@asisadh
Created March 17, 2019 11:38
Show Gist options
  • Save asisadh/908c5bec3ba757f8a725660243131757 to your computer and use it in GitHub Desktop.
Save asisadh/908c5bec3ba757f8a725660243131757 to your computer and use it in GitHub Desktop.
UITextField Extension
extension UITextField {
func underlined(){
let border = CALayer()
let width = CGFloat(2.0)
if let widthOfText = self.attributedText?.size().width{
border.borderColor = UIColor.primaryColor.cgColor
border.frame = CGRect(x: self.frame.size.width - widthOfText, y: self.frame.size.height - width, width: widthOfText, height: self.frame.size.height)
border.borderWidth = width
self.layer.addSublayer(border)
self.layer.masksToBounds = true
}
}
func hideUnderline(){
let border = CALayer()
let width = CGFloat(2.0)
border.borderColor = UIColor.white.cgColor
border.frame = CGRect(x: 0, y: self.frame.size.height - width, width: self.frame.size.width, height: self.frame.size.height)
border.borderWidth = width
self.layer.addSublayer(border)
self.layer.masksToBounds = true
}
func removeUnderline(){
if let subLayers = self.layer.sublayers{
for layers in subLayers{
layers.removeFromSuperlayer()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment