Commit df29bb15 authored by Steven杜宇's avatar Steven杜宇

// 字数限制

parent eaeb8a6f
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
0468D47E2B68CEA200CFB916 /* YHImagePickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0468D47D2B68CEA200CFB916 /* YHImagePickerView.swift */; }; 0468D47E2B68CEA200CFB916 /* YHImagePickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0468D47D2B68CEA200CFB916 /* YHImagePickerView.swift */; };
0468D4802B6914E600CFB916 /* YHSelectCountryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0468D47F2B6914E600CFB916 /* YHSelectCountryViewController.swift */; }; 0468D4802B6914E600CFB916 /* YHSelectCountryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0468D47F2B6914E600CFB916 /* YHSelectCountryViewController.swift */; };
0468D4822B6A2A8500CFB916 /* YHSelectCountryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0468D4812B6A2A8500CFB916 /* YHSelectCountryViewModel.swift */; }; 0468D4822B6A2A8500CFB916 /* YHSelectCountryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0468D4812B6A2A8500CFB916 /* YHSelectCountryViewModel.swift */; };
04754A952B96FF3D00F8ADCA /* UITextField+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04754A942B96FF3D00F8ADCA /* UITextField+Extension.swift */; };
04808C062B4686510056D53C /* ATAuthSDK.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 04808C042B4686510056D53C /* ATAuthSDK.bundle */; }; 04808C062B4686510056D53C /* ATAuthSDK.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 04808C042B4686510056D53C /* ATAuthSDK.bundle */; };
04808C082B4686C10056D53C /* ATAuthSDK_D.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 04808C032B4686510056D53C /* ATAuthSDK_D.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 04808C082B4686C10056D53C /* ATAuthSDK_D.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 04808C032B4686510056D53C /* ATAuthSDK_D.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
049A48A82B49417300D0C641 /* YHAboutUsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049A48A72B49417300D0C641 /* YHAboutUsViewController.swift */; }; 049A48A82B49417300D0C641 /* YHAboutUsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049A48A72B49417300D0C641 /* YHAboutUsViewController.swift */; };
...@@ -379,6 +380,7 @@ ...@@ -379,6 +380,7 @@
0468D47D2B68CEA200CFB916 /* YHImagePickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHImagePickerView.swift; sourceTree = "<group>"; }; 0468D47D2B68CEA200CFB916 /* YHImagePickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHImagePickerView.swift; sourceTree = "<group>"; };
0468D47F2B6914E600CFB916 /* YHSelectCountryViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHSelectCountryViewController.swift; sourceTree = "<group>"; }; 0468D47F2B6914E600CFB916 /* YHSelectCountryViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHSelectCountryViewController.swift; sourceTree = "<group>"; };
0468D4812B6A2A8500CFB916 /* YHSelectCountryViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHSelectCountryViewModel.swift; sourceTree = "<group>"; }; 0468D4812B6A2A8500CFB916 /* YHSelectCountryViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHSelectCountryViewModel.swift; sourceTree = "<group>"; };
04754A942B96FF3D00F8ADCA /* UITextField+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextField+Extension.swift"; sourceTree = "<group>"; };
04808C032B4686510056D53C /* ATAuthSDK_D.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = ATAuthSDK_D.framework; sourceTree = "<group>"; }; 04808C032B4686510056D53C /* ATAuthSDK_D.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = ATAuthSDK_D.framework; sourceTree = "<group>"; };
04808C042B4686510056D53C /* ATAuthSDK.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = ATAuthSDK.bundle; sourceTree = "<group>"; }; 04808C042B4686510056D53C /* ATAuthSDK.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = ATAuthSDK.bundle; sourceTree = "<group>"; };
049A48A72B49417300D0C641 /* YHAboutUsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAboutUsViewController.swift; sourceTree = "<group>"; }; 049A48A72B49417300D0C641 /* YHAboutUsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAboutUsViewController.swift; sourceTree = "<group>"; };
...@@ -1367,6 +1369,7 @@ ...@@ -1367,6 +1369,7 @@
A5ACE9022B4564F7002C94D2 /* AppDelegate+Extension.swift */, A5ACE9022B4564F7002C94D2 /* AppDelegate+Extension.swift */,
A5ACE9032B4564F7002C94D2 /* UILable+Extension.swift */, A5ACE9032B4564F7002C94D2 /* UILable+Extension.swift */,
A5ACE9042B4564F7002C94D2 /* Array+Extension.swift */, A5ACE9042B4564F7002C94D2 /* Array+Extension.swift */,
04754A942B96FF3D00F8ADCA /* UITextField+Extension.swift */,
); );
path = Extention; path = Extention;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -1909,6 +1912,7 @@ ...@@ -1909,6 +1912,7 @@
A5ACE9412B4564F7002C94D2 /* Dictionary+Extension.swift in Sources */, A5ACE9412B4564F7002C94D2 /* Dictionary+Extension.swift in Sources */,
A5C5B3102B57677300A7C5D1 /* YHGestureTableView.swift in Sources */, A5C5B3102B57677300A7C5D1 /* YHGestureTableView.swift in Sources */,
A5167B272B692CF20084C08F /* YHPreviewInfoCertificatePictureItemView.swift in Sources */, A5167B272B692CF20084C08F /* YHPreviewInfoCertificatePictureItemView.swift in Sources */,
04754A952B96FF3D00F8ADCA /* UITextField+Extension.swift in Sources */,
A5ACE9312B4564F7002C94D2 /* YHPersonalCenterCell.swift in Sources */, A5ACE9312B4564F7002C94D2 /* YHPersonalCenterCell.swift in Sources */,
04E86E5D2B84CC9700A35F4B /* YHWorkExampleMessageView.swift in Sources */, 04E86E5D2B84CC9700A35F4B /* YHWorkExampleMessageView.swift in Sources */,
A5ACE9532B4564F7002C94D2 /* YHBaseViewController.swift in Sources */, A5ACE9532B4564F7002C94D2 /* YHBaseViewController.swift in Sources */,
......
...@@ -268,10 +268,10 @@ extension YHChildPrimaryInfoVC : UITableViewDelegate, UITableViewDataSource { ...@@ -268,10 +268,10 @@ extension YHChildPrimaryInfoVC : UITableViewDelegate, UITableViewDataSource {
cell.text = detailItem.value cell.text = detailItem.value
cell.setTips(detailItem.tips, isShow:isNeedShowError && detailItem.isShowTips) cell.setTips(detailItem.tips, isShow:isNeedShowError && detailItem.isShowTips)
cell.textInputCondtion = { cell.textInputCondtion = {
text in textField in
if let textStr = text { if let textStr = textField.text {
let max = 100 let max = 100
text = textStr.count > max ? textStr[safe: ..<max] : textStr textField.text = textStr.count > max ? textStr[safe: ..<max] : textStr
} }
return true return true
} }
......
...@@ -234,10 +234,10 @@ extension YHSpousePrimaryInfoVC : UITableViewDelegate, UITableViewDataSource { ...@@ -234,10 +234,10 @@ extension YHSpousePrimaryInfoVC : UITableViewDelegate, UITableViewDataSource {
cell.placeHolder = detailItem.placeHolder cell.placeHolder = detailItem.placeHolder
cell.setTips(detailItem.tips, isShow: isNeedShowError && detailItem.isShowTips) cell.setTips(detailItem.tips, isShow: isNeedShowError && detailItem.isShowTips)
cell.textInputCondtion = { cell.textInputCondtion = {
text in textField in
if let textStr = text { if let textStr = textField.text {
let max = 100 let max = 100
text = textStr.count > max ? textStr[safe: ..<max] : textStr textField.text = textStr.count > max ? textStr[safe: ..<max] : textStr
} }
return true return true
} }
......
...@@ -153,6 +153,28 @@ extension YHCertificateInfoController : UITableViewDelegate, UITableViewDataSour ...@@ -153,6 +153,28 @@ extension YHCertificateInfoController : UITableViewDelegate, UITableViewDataSour
cell.title = detailItem.getTitle() cell.title = detailItem.getTitle()
cell.text = detailItem.value cell.text = detailItem.value
cell.setTips(detailItem.tips, isShow: isNeedShowError && detailItem.isShowTips) cell.setTips(detailItem.tips, isShow: isNeedShowError && detailItem.isShowTips)
cell.textInputCondtion = {
textField in
var max = -1
if detailItem.type == .chinaIdentityCardNumber { // 身份证
max = 18
} else if detailItem.type == .certificateSignPlace { // 签发地
max = 100
} else if detailItem.type == .traverlPassportNumber ||
detailItem.type == .certificateNumber {
max = 50
}
if max > 0 {
if let textStr = textField.text {
textField.text = (textStr.count > max ? textStr[safe: ..<max] : textStr)
}
}
return true
}
cell.textChange = { cell.textChange = {
[weak self] (text, isEditEnd) in [weak self] (text, isEditEnd) in
guard let self = self else { return } guard let self = self else { return }
......
...@@ -22,7 +22,7 @@ class YHFormItemInputTextCell: UITableViewCell { ...@@ -22,7 +22,7 @@ class YHFormItemInputTextCell: UITableViewCell {
} }
// BOOL值表示编辑是否结束 // BOOL值表示编辑是否结束
var textChange:((String?, Bool)->Void)? var textChange:((String?, Bool)->Void)?
var textInputCondtion:((inout String?)->Bool)? var textInputCondtion:((UITextField)->Bool)?
var title:String? { var title:String? {
didSet { didSet {
...@@ -165,7 +165,7 @@ class YHFormItemInputTextCell: UITableViewCell { ...@@ -165,7 +165,7 @@ class YHFormItemInputTextCell: UITableViewCell {
@objc func textFieldChanged(textField:UITextField) { @objc func textFieldChanged(textField:UITextField) {
if let textChange = textChange { if let textChange = textChange {
if let textInputCondtion = textInputCondtion { if let textInputCondtion = textInputCondtion {
if textInputCondtion(&textField.text) { if textInputCondtion(self.textField) {
textChange(textField.text, false) textChange(textField.text, false)
} }
} else { } else {
...@@ -177,7 +177,7 @@ class YHFormItemInputTextCell: UITableViewCell { ...@@ -177,7 +177,7 @@ class YHFormItemInputTextCell: UITableViewCell {
@objc func textFieldEditEnd(textField:UITextField) { @objc func textFieldEditEnd(textField:UITextField) {
if let textChange = textChange { if let textChange = textChange {
if let textInputCondtion = textInputCondtion { if let textInputCondtion = textInputCondtion {
if textInputCondtion(&textField.text) { if textInputCondtion(self.textField) {
textChange(textField.text, true) textChange(textField.text, true)
} }
} else { } else {
......
//
// UITextField+Extension.swift
// galaxy
//
// Created by edy on 2024/3/5.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
extension UITextField {
/// 限制textField输入
public func limitInputWithPattern(pattern: String, _ limitCount: Int = -1) {
// 非markedText才继续往下处理
guard let _: UITextRange = self.markedTextRange else {
// 当前光标的位置(后面会对其做修改)
let cursorPostion = self.offset(from: self.endOfDocument, to: self.selectedTextRange!.end)
// 替换后的字符串
var str = ""
if pattern == "" {
str = self.text!
} else {
str = self.text!.regularReplace(pattern: pattern, with: "")
}
// 如果长度超过限制则直接截断
if limitCount >= 0, str.count > limitCount {
str = String(str.prefix(limitCount))
}
self.text = str
// 让光标停留在正确位置
let targetPostion = self.position(from: self.endOfDocument, offset: cursorPostion)!
self.selectedTextRange = self.textRange(from: targetPostion, to: targetPostion)
return
}
}
}
extension String {
// 使用正则表达式替换
func regularReplace(pattern: String, with: String, options: NSRegularExpression.Options = []) -> String {
let regex = try! NSRegularExpression(pattern: pattern, options: options)
return regex.stringByReplacingMatches(in: self, options: [],
range: NSMakeRange(0, self.count),
withTemplate: with)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment