mohammad-i
12/14/2017 - 12:54 AM

Underline UITextField

draw only the bottom border of the text field

import UIKit

class UnderlineTextField: UITextField {

	var underlineWidth:CGFloat = 0.0
	
	required init?(coder aDecoder: NSCoder) {
		super.init(coder: aDecoder)
		tintColor = UIColor.init(named: "gflGreen")
		borderStyle = .none
		
		font = Utilities.getFont(.calibreRegular, size: 18.0)
		textColor = UIColor.init(named: "slateGrayBodyText")
		adjustsFontForContentSizeCategory = true
		
		let border = CALayer()
		border.borderColor = UIColor.init(named: "silverSemiTransTwo")?.cgColor
		border.frame = CGRect(x: 0, y: self.frame.size.height - (underlineWidth * 5), width:  self.frame.size.width, height: underlineWidth)
		border.borderWidth = underlineWidth
		layer.addSublayer(border)
		layer.masksToBounds = true
	}
	
}