Created
April 16, 2019 17:51
-
-
Save gsanthosh91/08fa5d4f3ea26515ebc80155acac3f37 to your computer and use it in GitHub Desktop.
iOS UITextField with corner radius
This file contains hidden or 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
| import Foundation | |
| import UIKit | |
| class SATextField: UITextField { | |
| override init(frame: CGRect) { | |
| super.init(frame: frame) | |
| setUpField() | |
| } | |
| required init?(coder aDecoder: NSCoder) { | |
| super.init( coder: aDecoder ) | |
| setUpField() | |
| } | |
| private func setUpField() { | |
| tintColor = .white | |
| textColor = .black | |
| font = UIFont(name: "HelveticaNeue-Medium", size: 18) | |
| backgroundColor = UIColor(white: 1.0, alpha: 0.7) | |
| autocorrectionType = .no | |
| layer.cornerRadius = 25.0 | |
| clipsToBounds = true | |
| let placeholder = self.placeholder != nil ? self.placeholder! : "" | |
| let placeholderFont = UIFont(name: "HelveticaNeue-Light", size: 18)! | |
| attributedPlaceholder = NSAttributedString(string: placeholder, attributes: | |
| [NSAttributedString.Key.foregroundColor: UIColor.lightGray, | |
| NSAttributedString.Key.font: placeholderFont]) | |
| let indentView = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 20)) | |
| leftView = indentView | |
| leftViewMode = .always | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment