Skip to content

Instantly share code, notes, and snippets.

@jarrodnorwell
Last active July 4, 2023 11:55
Show Gist options
  • Save jarrodnorwell/0f0c4d513b594186d4840a0b43b337b4 to your computer and use it in GitHub Desktop.
Save jarrodnorwell/0f0c4d513b594186d4840a0b43b337b4 to your computer and use it in GitHub Desktop.
//
// MinimalRoundedTextField.swift
// AppNameHere
//
// Created by Antique on 4/7/2023.
//
import Foundation
import UIKit
enum RoundedCorners {
case bottom, none, top
}
class MinimalRoundedTextField : UITextField {
init(_ placeholder: String, _ roundedCorners: RoundedCorners = .none, _ radius: CGFloat = 15) {
super.init(frame: .zero)
self.backgroundColor = .secondarySystemBackground
self.placeholder = placeholder
switch roundedCorners {
case .bottom, .top:
self.layer.cornerCurve = .continuous
self.layer.cornerRadius = radius
self.layer.maskedCorners = roundedCorners == .bottom ? [.layerMinXMaxYCorner, .layerMaxXMaxYCorner] : [.layerMinXMinYCorner, .layerMaxXMinYCorner]
case .none:
break
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func editingRect(forBounds bounds: CGRect) -> CGRect {
return bounds.insetBy(dx: 20, dy: 0)
}
override func placeholderRect(forBounds bounds: CGRect) -> CGRect {
return editingRect(forBounds: bounds)
}
override func textRect(forBounds bounds: CGRect) -> CGRect {
return editingRect(forBounds: bounds)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment