How to add underline to UITextField in Swift 3

UITextField Underlined In Swift 3

Create a custom UITexField and add this method to it then override

layoutSubviews() and call it from there

    func underlined(){
        let border = CALayer()
        let lineWidth = CGFloat(0.3)
        border.borderColor = UIColor.lightGray.cgColor
        border.frame = CGRect(x: 0, y: self.frame.size.height - lineWidth, width:  self.frame.size.width, height: self.frame.size.height)
        border.borderWidth = lineWidth
        self.layer.addSublayer(border)
        self.layer.masksToBounds = true
    }

Good to know How to change UITextField placeholder color

Custom UITableViewCell from xib file in Swift 3

Create the custom UITableViewCell from a xib file

In this tutorial we will create a custom cell from xib file and learn how to use it in UITableView using Swift 3

Create Xcode project

1- Create a new Xcode project and select “Single View Application” template and click next

2- Type you project name, in my case i named it “CellExample” and select Swift from Language list and iPhone from Devices list and click next

custom uitableviewcell from xib in swift

3- select a location for your project then click finish.

Create UITableViewCell class and xib

4-Now create a new file and select “Cocoa Touch Class” and press next Continue reading “Custom UITableViewCell from xib file in Swift 3”