Skip to content

Commit

Permalink
✨ Feat: #2 - placeHolder를 커스텀하게 조절합시다~ (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
usa4060 authored Oct 27, 2023
1 parent aec21b6 commit 03eabc3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ final class SignInViewController: BaseViewController {
textFieldSubTitle: "비밀번호",
accessoryType: .image(image: CMCAsset._24x24hide.image),
keyboardType: .emailAddress

)
textField.accessoryButton.setImage(CMCAsset._24x24show.image, for: .selected)
return textField
}()

Expand Down
38 changes: 35 additions & 3 deletions DesignSystem/Sources/CMCTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,24 @@ public final class CMCTextField: UIView{
}

// MARK: - UI
fileprivate lazy var textField: UITextField = {
let textField = UITextField()
fileprivate lazy var textField: CustomTextField = {
let textField = CustomTextField()
let leftPadding = UIView(frame: CGRect(x: 0, y: 0, width: 18, height: textField.frame.height))
let rightPadding = UIView(frame: CGRect(x: 0, y: 0, width: 18, height: textField.frame.height))
textField.leftView = leftPadding
textField.rightView = rightPadding
textField.leftViewMode = .always
textField.rightViewMode = .always
textField.placeholder = placeHolder
textField.layer.cornerRadius = 5
textField.layer.borderWidth = 1
textField.keyboardType = keyboardType
textField.font = DesignSystemFontFamily.Pretendard.medium.font(size: 15)
textField.textColor = DesignSystemAsset.gray50.color
let attributes = [
NSAttributedString.Key.foregroundColor: DesignSystemAsset.gray700.color,
NSAttributedString.Key.font: DesignSystemFontFamily.Pretendard.medium.font(size: 15)
]
textField.attributedPlaceholder = NSAttributedString(string: placeHolder, attributes: attributes)
return textField
}()

Expand Down Expand Up @@ -280,6 +284,34 @@ extension CMCTextField{

}

class CustomTextField: UITextField {
override func placeholderRect(forBounds bounds: CGRect) -> CGRect {
return CGRect(
x: bounds.origin.x + 18,
y: bounds.origin.y,
width: bounds.width,
height: bounds.height
)
}

override func textRect(forBounds bounds: CGRect) -> CGRect {
return CGRect(
x: bounds.origin.x + 18,
y: bounds.origin.y,
width: bounds.width,
height: bounds.height
)
}

override func editingRect(forBounds bounds: CGRect) -> CGRect {
return CGRect(
x: bounds.origin.x + 18,
y: bounds.origin.y,
width: bounds.width,
height: bounds.height
)
}
}

extension CMCTextField: UITextFieldDelegate {

Expand Down

0 comments on commit 03eabc3

Please sign in to comment.