Skip to content

tareqalhammoodi/TextFieldStyle-Swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

UITextField underline style extension - Swift

Sample

How to use?

  1. Add this extension to your code.

      extension UIView {
         func addBottomBorder(color: UIColor, width: CGFloat) {
             let border = CALayer()
             border.backgroundColor = color.cgColor
             border.frame = CGRect(x: 0, y: frame.size.height - width,
                                   width: frame.size.width - 25, height: width)
             layer.addSublayer(border)
         }
     }
    
  2. Make sure you have imported UIKit framework.

    import UIKit
    
  3. Then inside your ViewController file call addBottomBorder() from viewDidLayoutSubviews() function as shown bellow:

    override func viewDidLayoutSubviews() {
         super.viewDidLayoutSubviews()
    
         yourTextFieldName.addBottomBorder(color: .gray, width: 0.5)
    
    }
    
  4. Make sure your text field has no background color to have the same look. (Optional)

    yourTextFieldName.backgroundColor = .clear
    

Final Output

Need Help?

You can reach me on Twitter.

Buying me a cookie will be appreciated :)

About

UITextField underline style extension - Swift

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages