79 lines
2.0 KiB
Swift
79 lines
2.0 KiB
Swift
//
|
|
// PasswordSetView.swift
|
|
// yinmeng-ios
|
|
//
|
|
// Created by MaiMang on 2024/3/1.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class PasswordSetView: UIView {
|
|
|
|
|
|
var placeHolder:String? {
|
|
didSet {
|
|
let attribute = NSMutableAttributedString(string: placeHolder ?? "", attributes: [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 16), NSAttributedString.Key.foregroundColor:UIColor.placeholderText])
|
|
textFiled.attributedPlaceholder = attribute
|
|
}
|
|
}
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
backgroundColor = .white
|
|
layer.masksToBounds = true
|
|
layer.cornerRadius = 25
|
|
addSubview(textFiled)
|
|
addSubview(eyeBtn)
|
|
|
|
textFiled.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(15)
|
|
make.top.bottom.equalToSuperview()
|
|
make.right.equalTo(eyeBtn.snp.left).offset(-10)
|
|
}
|
|
|
|
eyeBtn.snp.makeConstraints { make in
|
|
make.size.equalTo(CGSize(width: 18, height: 18))
|
|
make.centerY.equalToSuperview()
|
|
make.right.equalTo(self).offset(-15)
|
|
}
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
lazy var textFiled:UITextField = {
|
|
let view = UITextField()
|
|
view.textColor = .firstText
|
|
view.font = UIFont.systemFont(ofSize: 16)
|
|
view.tintColor = ThemeColor(hexStr: "#282828")
|
|
view.isSecureTextEntry = true
|
|
view.addTarget(self, action: #selector(phoneTextFiledDidChange), for: .editingChanged)
|
|
return view
|
|
}()
|
|
|
|
private lazy var eyeBtn: UIButton = {
|
|
let button = UIButton(type: .custom)
|
|
button.setImage(UIImage(named: "user_eye"), for: .normal)
|
|
button.setImage(UIImage(named: "user_eye_open"), for: .selected)
|
|
button.addTarget(self, action: #selector(eyeClick), for: .touchUpInside)
|
|
return button
|
|
}()
|
|
|
|
@objc func eyeClick() {
|
|
eyeBtn.isSelected = !eyeBtn.isSelected
|
|
textFiled.isSecureTextEntry = !textFiled.isSecureTextEntry
|
|
}
|
|
|
|
|
|
@objc func phoneTextFiledDidChange(_ textField: UITextField) {
|
|
if let text = textField.text {
|
|
if text.count > 16 {
|
|
textField.text = text.substring(start: 0, 16)
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|