1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// KWMCustomsClearanceVC.m
// iCemarose
//
// Created by HouWeiBin on 2017/6/28.
// Copyright © 2017年 kollway. All rights reserved.
//
#import "KWMCustomsClearanceVC.h"
#import "KWMStringUtil.h"
@interface KWMCustomsClearanceVC ()
@property (weak, nonatomic) IBOutlet UITextField *tfName;
@property (weak, nonatomic) IBOutlet UITextField *tfIdCode;
@end
@implementation KWMCustomsClearanceVC
- (void)viewDidLoad {
[super viewDidLoad];
[self initView];
}
-(void)initView{
[self initTitle];
[self initTf];
}
-(void)initTitle{
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(onClickLeftButton)];
self.navigationItem.leftBarButtonItem = leftButton;
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"存储" style:UIBarButtonItemStylePlain target:self action:@selector(onClickRightButton)];
self.navigationItem.rightBarButtonItem = rightButton;
}
-(void)initTf{
self.tfName.borderStyle = UITextBorderStyleNone;
self.tfIdCode.borderStyle = UITextBorderStyleNone;
self.tfIdCode.delegate = self;
self.customsClearance = [KWMCustomsClearance new];
self.customsClearance.name = @"侯卫彬";
self.customsClearance.idCode = @"445222199211153557";
if(self.customsClearance){
self.tfName.text = self.customsClearance.name;
self.tfIdCode.text = self.customsClearance.idCode;
if(self.customsClearance.idCode.length >10){
self.tfIdCode.text = [self halfSecretCode:self.customsClearance.idCode];
}
}else{
self.customsClearance = [KWMCustomsClearance new];
}
}
-(void)onClickLeftButton{
[self.navigationController popViewControllerAnimated:YES];
}
-(void)onClickRightButton{
NSString *name = self.tfName.text;
NSString *idCode = self.tfIdCode.text;
if([KWMStringUtil isEmpty:name]){
[self showToast:@"请填写姓名"];
}else if([KWMStringUtil isEmpty:idCode]){
[self showToast:@"请填写身份证号"];
}else{
//身份证是否为没有编辑过--如果是且仍为半密文状态.
BOOL noEdited = [self.tfIdCode.text rangeOfString:@"***"].location != NSNotFound;
self.customsClearance.name = self.tfName.text;
self.customsClearance.idCode = noEdited?self.customsClearance.idCode:self.tfIdCode.text;
if(self.delegate){
[self.delegate kwm_customsClearance:self.customsClearance];
}
[self.navigationController popViewControllerAnimated:YES];
}
}
#pragma mark -- idCode StringUtil
//替换字符串 445555199011123333 => 44555************3
-(NSString *)halfSecretCode:(NSString *)idCode{
NSString *mIdCode = self.customsClearance.idCode;
NSMutableString *secretCode = [[NSMutableString alloc] init];
for (NSInteger i = 0; i < idCode.length - 6; i++) {
[secretCode appendString:@"*"];
}
NSString *halfSecretCode = [mIdCode stringByReplacingCharactersInRange:NSMakeRange(5, mIdCode.length-6) withString:secretCode];
return halfSecretCode;
}
#pragma mark -- UITextFiledDelegate
-(void)textFieldDidBeginEditing:(UITextField *)textField{
textField.clearsOnBeginEditing = NO;
}
//简单的输入限制 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:ALPHANUM] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
return [string isEqualToString:filtered];
}
@end