Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
extension UITextField {
func underlined(){
let border = CALayer()
let width = CGFloat(1.0)
border.borderColor = UIColor.lightGrayColor().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
}
}
// Call with....
yourTextField.underlined()
@d33pak-s1ngh

This comment has been minimized.

Copy link

d33pak-s1ngh commented Mar 12, 2018

i have applied this method to my textview and i can not see any bottom border in that textview.

@minwoolee

This comment has been minimized.

Copy link

minwoolee commented Mar 5, 2019

I read somewhere that bounds property is required. Adding this line worked for me

border.bounds = CGRect(x: 0, y: 0, width:  self.frame.size.width, height: self.frame.size.height)
@Sopharethraksmey

This comment has been minimized.

Copy link

Sopharethraksmey commented Mar 29, 2019

I have applied this method and it seem working fine but cannot apply all screen device.
let border = CALayer()
let width = CGFloat(1.0)
border.borderColor = UIColor.lightGray.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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.