Skip to content
Snippets Groups Projects
Commit 15a046e7 authored by Bruno Muniz's avatar Bruno Muniz :apple:
Browse files

Created outline style for input field

parent 2732eebc
No related branches found
No related tags found
3 merge requests!54Releasing 1.1.4,!43Created outline style for input field,!42Adding SFTP as a service to backup/restore
import UIKit
import Shared
import Combine
public final class OutlinedInputField: UIView {
let textField = UITextField()
let placeholderLabel = UILabel()
public var textPublisher: AnyPublisher<String, Never> {
textField.textPublisher
}
public init() {
super.init(frame: .zero)
layer.borderWidth = 1.0
layer.cornerRadius = 4.0
layer.masksToBounds = true
layer.borderColor = Asset.neutralWeak.color.cgColor
textField.delegate = self
textField.backgroundColor = .clear
placeholderLabel.textColor = Asset.neutralWeak.color
placeholderLabel.font = Fonts.Mulish.regular.font(size: 16.0)
addSubview(placeholderLabel)
addSubview(textField)
placeholderLabel.snp.makeConstraints {
$0.top.equalToSuperview().offset(15)
$0.left.equalToSuperview().offset(15)
$0.right.lessThanOrEqualToSuperview().offset(-15)
$0.bottom.equalToSuperview().offset(-18)
}
textField.snp.makeConstraints {
$0.top.equalToSuperview().offset(15)
$0.left.equalToSuperview().offset(15)
$0.right.equalToSuperview().offset(-15)
$0.bottom.equalToSuperview().offset(-18)
}
}
required init?(coder: NSCoder) { nil }
public func setup(title: String) {
placeholderLabel.text = title
}
}
extension OutlinedInputField: UITextFieldDelegate {
public func textField(
_ textField: UITextField,
shouldChangeCharactersIn range: NSRange,
replacementString string: String
) -> Bool {
placeholderLabel.alpha = (textField.text! as NSString)
.replacingCharacters(in: range, with: string)
.count > 0 ? 0.0 : 1.0
return true
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment