Last active
November 6, 2019 07:09
-
-
Save mcz9mm/94371a0f37ba20c2b9338eed28235d79 to your computer and use it in GitHub Desktop.
This file contains 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 UIKit | |
@IBDesignable class PaddingTextField: UITextField { | |
// MARK: Properties | |
@IBInspectable var padding: CGPoint = CGPoint(x: 6.0, y: 0.0) | |
// MARK: Internal Methods | |
override func textRect(forBounds bounds: CGRect) -> CGRect { | |
return bounds.insetBy(dx: self.padding.x, dy: self.padding.y) | |
} | |
override func editingRect(forBounds bounds: CGRect) -> CGRect { | |
return bounds.insetBy(dx: self.padding.x, dy: self.padding.y) | |
} | |
override func placeholderRect(forBounds bounds: CGRect) -> CGRect { | |
return bounds.insetBy(dx: self.padding.x, dy: self.padding.y) | |
} | |
} | |
extension UITextField { | |
func setLeftPaddingPoints(_ amount:CGFloat){ | |
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height)) | |
self.leftView = paddingView | |
self.leftViewMode = .always | |
} | |
func setRightPaddingPoints(_ amount:CGFloat) { | |
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height)) | |
self.rightView = paddingView | |
self.rightViewMode = .always | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment