-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
:: [#256] MG+TitleTextFieldView
- Loading branch information
Showing
4 changed files
with
112 additions
and
161 deletions.
There are no files selected for viewing
70 changes: 0 additions & 70 deletions
70
Projects/Modules/DSKit/Sources/Components/MaeumGaGymTextField/MG+TitleTextField.swift
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
Projects/Modules/DSKit/Sources/Components/MaeumGaGymTextField/TitleTextFieldType.swift
This file was deleted.
Oops, something went wrong.
112 changes: 112 additions & 0 deletions
112
Projects/Modules/DSKit/Sources/Components/MaeumGaGymVIew/MG+TitleTextFieldView.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import UIKit | ||
|
||
import SnapKit | ||
import Then | ||
|
||
import Core | ||
|
||
open class MGTitleTextFieldView: BaseView { | ||
|
||
private var textLimit: Int = 0 | ||
|
||
private var titleLabel = UILabel().then { | ||
$0.font = UIFont.Pretendard.bodyMedium | ||
$0.textColor = .black | ||
$0.textAlignment = .left | ||
} | ||
|
||
private var containerView = BaseView().then { | ||
$0.layer.borderWidth = 1 | ||
$0.layer.borderColor = DSKitAsset.Colors.gray50.color.cgColor | ||
$0.layer.cornerRadius = 8.0 | ||
$0.backgroundColor = DSKitAsset.Colors.gray25.color | ||
} | ||
|
||
public let textField = UITextField().then { | ||
$0.tintColor = DSKitAsset.Colors.blue500.color | ||
$0.font = UIFont.Pretendard.bodyLarge | ||
} | ||
|
||
private var unitLabel = MGLabel(font: UIFont.Pretendard.bodyLarge, | ||
textColor: DSKitAsset.Colors.gray600.color).then { | ||
$0.isHidden = true | ||
} | ||
|
||
public init (titleText: String, | ||
unitText: String? = "", | ||
textLimit: Int, | ||
placeholder: String | ||
) { | ||
super.init(frame: .zero) | ||
|
||
titleLabel.text = titleText | ||
if !(unitText == "") { | ||
unitLabel.isHidden = false | ||
unitLabel.changeText(text: unitText) | ||
} | ||
self.textField.placeholder = placeholder | ||
self.textLimit = textLimit | ||
} | ||
|
||
required public init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
open override func attribute() { | ||
super.attribute() | ||
|
||
textField.delegate = self | ||
} | ||
|
||
open override func layout() { | ||
super.layout() | ||
|
||
addSubviews([titleLabel, containerView]) | ||
containerView.addSubviews([textField, unitLabel]) | ||
|
||
titleLabel.snp.makeConstraints { | ||
$0.top.leading.trailing.equalToSuperview() | ||
$0.height.equalTo(20.0) | ||
} | ||
|
||
containerView.snp.makeConstraints { | ||
$0.leading.trailing.equalToSuperview() | ||
$0.top.equalTo(titleLabel.snp.bottom).offset(8.0) | ||
$0.bottom.equalToSuperview() | ||
} | ||
|
||
textField.snp.makeConstraints { | ||
$0.top.equalToSuperview().offset(12.0) | ||
$0.leading.trailing.equalToSuperview().inset(12.0) | ||
$0.bottom.equalToSuperview().inset(12.0) | ||
} | ||
|
||
unitLabel.snp.makeConstraints { | ||
$0.top.bottom.trailing.equalToSuperview().inset(12.0) | ||
$0.height.equalTo(24.0) | ||
} | ||
} | ||
} | ||
|
||
extension MGTitleTextFieldView: UITextFieldDelegate { | ||
public func textFieldDidBeginEditing(_ textField: UITextField) { | ||
containerView.layer.borderColor = DSKitAsset.Colors.blue100.color.cgColor | ||
containerView.backgroundColor = DSKitAsset.Colors.blue50.color | ||
titleLabel.textColor = DSKitAsset.Colors.blue500.color | ||
} | ||
|
||
public func textFieldDidEndEditing(_ textField: UITextField) { | ||
containerView.layer.borderColor = DSKitAsset.Colors.gray50.color.cgColor | ||
containerView.backgroundColor = DSKitAsset.Colors.gray25.color | ||
titleLabel.textColor = .black | ||
} | ||
|
||
public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { | ||
let currentText = textField.text ?? "" | ||
guard let stringRange = Range(range, in: currentText) else { return false } | ||
|
||
let updatedText = currentText.replacingCharacters(in: stringRange, with: string) | ||
|
||
return updatedText.count <= textLimit | ||
} | ||
} |
57 changes: 0 additions & 57 deletions
57
Projects/Modules/DSKit/Sources/Components/MaeumGaGymVIew/MG+TitleTextView.swift
This file was deleted.
Oops, something went wrong.