Last active
July 6, 2020 11:12
-
-
Save tonyedwardspz/82e753fc1934a421095b to your computer and use it in GitHub Desktop.
Underlined UITextView in Swift - http://purelywebdesign.co.uk/tutorial/swift-underlined-text-field-tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
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)
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
i have applied this method to my textview and i can not see any bottom border in that textview.