Created
April 2, 2022 22:07
-
-
Save jakehawken/fdf71d1a108a51104ebcef5e727a86d6 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
// InsetTextField.swift | |
// Created by Jacob Hawken on 4/2/22. | |
import UIKit | |
class InsetTextField: UITextField { | |
var leftInset: CGFloat = 8 { didSet { setNeedsLayout() } } | |
var rightInset: CGFloat = 8 { didSet { setNeedsLayout() } } | |
var topInset: CGFloat = 8 { didSet { setNeedsLayout() } } | |
var bottomInset: CGFloat = 8 { didSet { setNeedsLayout() } } | |
var textInset: UIEdgeInsets { | |
UIEdgeInsets( | |
top: topInset, | |
left: leftInset, | |
bottom: bottomInset, | |
right: rightInset | |
) | |
} | |
/// Rect for placeholder | |
override func textRect(forBounds bounds: CGRect) -> CGRect { | |
bounds.inset(by: textInset) | |
} | |
// Rect for typed text | |
override func editingRect(forBounds bounds: CGRect) -> CGRect { | |
bounds.inset(by: textInset) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment