Skip to content

Instantly share code, notes, and snippets.

@gsanthosh91
Created April 16, 2019 17:51
Show Gist options
  • Select an option

  • Save gsanthosh91/08fa5d4f3ea26515ebc80155acac3f37 to your computer and use it in GitHub Desktop.

Select an option

Save gsanthosh91/08fa5d4f3ea26515ebc80155acac3f37 to your computer and use it in GitHub Desktop.
iOS UITextField with corner radius
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