Skip to content

Commit 1e3693e

Browse files
committed
Login Cell - 舍弃 xib
1 parent d6bb828 commit 1e3693e

13 files changed

Lines changed: 317 additions & 189 deletions

File tree

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@
464464
4EC461B31B39360F00D08970 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4EC461B01B39360F00D08970 /* [email protected] */; };
465465
4EC461B41B39360F00D08970 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4EC461B11B39360F00D08970 /* [email protected] */; };
466466
4EC461B71B3939DC00D08970 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4EC461B51B3939DC00D08970 /* [email protected] */; };
467+
4EC4800C1C2936DA005F1772 /* PhoneCodeButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EC4800B1C2936DA005F1772 /* PhoneCodeButton.m */; };
467468
4EC5AD921A258DF8006FA97C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4EC5AD8F1A258DF8006FA97C /* [email protected] */; };
468469
4EC5AD931A258DF8006FA97C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4EC5AD901A258DF8006FA97C /* [email protected] */; };
469470
4EC5AD941A258DF8006FA97C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4EC5AD911A258DF8006FA97C /* [email protected] */; };
@@ -867,7 +868,6 @@
867868
8EF643B019FF7E2900F7EEB0 /* CodingTipCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EF6436519FF7E2900F7EEB0 /* CodingTipCell.m */; };
868869
8EF643B119FF7E2900F7EEB0 /* ConversationCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EF6436719FF7E2900F7EEB0 /* ConversationCell.m */; };
869870
8EF643B619FF7E2900F7EEB0 /* Input_OnlyText_Cell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EF6436F19FF7E2900F7EEB0 /* Input_OnlyText_Cell.m */; };
870-
8EF643B719FF7E2900F7EEB0 /* Input_OnlyText_Cell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8EF6437019FF7E2900F7EEB0 /* Input_OnlyText_Cell.xib */; };
871871
8EF643B819FF7E2900F7EEB0 /* InputOnlyTextPlainCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EF6437219FF7E2900F7EEB0 /* InputOnlyTextPlainCell.m */; };
872872
8EF643B919FF7E2900F7EEB0 /* LeftImage_LRTextCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EF6437419FF7E2900F7EEB0 /* LeftImage_LRTextCell.m */; };
873873
8EF643BA19FF7E2900F7EEB0 /* MemberCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EF6437619FF7E2900F7EEB0 /* MemberCell.m */; };
@@ -1726,6 +1726,8 @@
17261726
4EC461B01B39360F00D08970 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
17271727
4EC461B11B39360F00D08970 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
17281728
4EC461B51B3939DC00D08970 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
1729+
4EC4800A1C2936DA005F1772 /* PhoneCodeButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PhoneCodeButton.h; sourceTree = "<group>"; };
1730+
4EC4800B1C2936DA005F1772 /* PhoneCodeButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PhoneCodeButton.m; sourceTree = "<group>"; };
17291731
4EC5AD8F1A258DF8006FA97C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
17301732
4EC5AD901A258DF8006FA97C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
17311733
4EC5AD911A258DF8006FA97C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
@@ -2328,7 +2330,6 @@
23282330
8EF6436719FF7E2900F7EEB0 /* ConversationCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConversationCell.m; sourceTree = "<group>"; };
23292331
8EF6436E19FF7E2900F7EEB0 /* Input_OnlyText_Cell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Input_OnlyText_Cell.h; sourceTree = "<group>"; };
23302332
8EF6436F19FF7E2900F7EEB0 /* Input_OnlyText_Cell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Input_OnlyText_Cell.m; sourceTree = "<group>"; };
2331-
8EF6437019FF7E2900F7EEB0 /* Input_OnlyText_Cell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Input_OnlyText_Cell.xib; sourceTree = "<group>"; };
23322333
8EF6437119FF7E2900F7EEB0 /* InputOnlyTextPlainCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InputOnlyTextPlainCell.h; sourceTree = "<group>"; };
23332334
8EF6437219FF7E2900F7EEB0 /* InputOnlyTextPlainCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InputOnlyTextPlainCell.m; sourceTree = "<group>"; };
23342335
8EF6437319FF7E2900F7EEB0 /* LeftImage_LRTextCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LeftImage_LRTextCell.h; sourceTree = "<group>"; };
@@ -4814,6 +4815,8 @@
48144815
923399711C00A9EF00F29E04 /* DashesLineView.m */,
48154816
D0A32BF11BF19EF100336C52 /* PopFliterMenu.h */,
48164817
D0A32BF21BF19EF100336C52 /* PopFliterMenu.m */,
4818+
4EC4800A1C2936DA005F1772 /* PhoneCodeButton.h */,
4819+
4EC4800B1C2936DA005F1772 /* PhoneCodeButton.m */,
48174820
);
48184821
path = Views;
48194822
sourceTree = "<group>";
@@ -4875,7 +4878,6 @@
48754878
8EF6436719FF7E2900F7EEB0 /* ConversationCell.m */,
48764879
8EF6436E19FF7E2900F7EEB0 /* Input_OnlyText_Cell.h */,
48774880
8EF6436F19FF7E2900F7EEB0 /* Input_OnlyText_Cell.m */,
4878-
8EF6437019FF7E2900F7EEB0 /* Input_OnlyText_Cell.xib */,
48794881
8EF6437119FF7E2900F7EEB0 /* InputOnlyTextPlainCell.h */,
48804882
8EF6437219FF7E2900F7EEB0 /* InputOnlyTextPlainCell.m */,
48814883
8EF6437319FF7E2900F7EEB0 /* LeftImage_LRTextCell.h */,
@@ -5235,7 +5237,6 @@
52355237
4E93F23A1B84356500017916 /* [email protected] in Resources */,
52365238
4E4D6AC21B252CD400FD2E49 /* [email protected] in Resources */,
52375239
8E97CEB01A0C7E26006F9AD7 /* [email protected] in Resources */,
5238-
8EF643B719FF7E2900F7EEB0 /* Input_OnlyText_Cell.xib in Resources */,
52395240
7E335D9D1B6F5E94003D0F3D /* [email protected] in Resources */,
52405241
4EF17ED71B3C3112003CDD2D /* [email protected] in Resources */,
52415242
4E6384031B33C8E900D98648 /* [email protected] in Resources */,
@@ -6181,6 +6182,7 @@
61816182
4E0BD86F1B6C7E3D0061CAA6 /* CSTopicDetailVC.m in Sources */,
61826183
8EF643C819FF7E2900F7EEB0 /* ToMessageCell.m in Sources */,
61836184
4E217F111A70EDC700F6DF88 /* SVWebViewControllerActivityChrome.m in Sources */,
6185+
4EC4800C1C2936DA005F1772 /* PhoneCodeButton.m in Sources */,
61846186
4E0BD86D1B6C7E3D0061CAA6 /* CSScrollview.m in Sources */,
61856187
D09AA5C01BFDEDD1008CA9EB /* NSString+Attribute.m in Sources */,
61866188
4EE1A2331B5D02CA004284F1 /* ProjectTopicsView.m in Sources */,

Coding_iOS/Controllers/Login/CannotLoginViewController.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ - (void)viewDidLoad
2727
// 添加myTableView
2828
_myTableView = ({
2929
TPKeyboardAvoidingTableView *tableView = [[TPKeyboardAvoidingTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
30-
[tableView registerNib:[UINib nibWithNibName:kCellIdentifier_Input_OnlyText_Cell bundle:[NSBundle mainBundle]] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell];
30+
[tableView registerClass:[Input_OnlyText_Cell class] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell_Text];
31+
[tableView registerClass:[Input_OnlyText_Cell class] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell_Captcha];
3132
tableView.backgroundColor = kColorTableSectionBg;
3233
tableView.dataSource = self;
3334
tableView.delegate = self;
@@ -134,18 +135,17 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
134135

135136
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
136137
{
137-
Input_OnlyText_Cell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_Input_OnlyText_Cell forIndexPath:indexPath];
138+
Input_OnlyText_Cell *cell = [tableView dequeueReusableCellWithIdentifier:(indexPath.row > 0? kCellIdentifier_Input_OnlyText_Cell_Captcha: kCellIdentifier_Input_OnlyText_Cell_Text) forIndexPath:indexPath];
138139

139140
__weak typeof(self) weakSelf = self;
140141
if (indexPath.row == 0) {
141142
cell.textField.keyboardType = UIKeyboardTypeEmailAddress;
142-
[cell configWithPlaceholder:@" 电子邮箱" andValue:self.email];
143+
[cell setPlaceholder:@" 电子邮箱" value:self.email];
143144
cell.textValueChangedBlock = ^(NSString *valueStr){
144145
weakSelf.email = valueStr;
145146
};
146147
}else{
147-
cell.isCaptcha = YES;
148-
[cell configWithPlaceholder:@" 验证码" andValue:self.j_captcha];
148+
[cell setPlaceholder:@" 验证码" value:self.j_captcha];
149149
cell.textValueChangedBlock = ^(NSString *valueStr){
150150
weakSelf.j_captcha = valueStr;
151151
};

Coding_iOS/Controllers/Login/LoginViewController.m

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ - (void)viewDidLoad
6363
_myTableView = ({
6464
TPKeyboardAvoidingTableView *tableView = [[TPKeyboardAvoidingTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
6565
[tableView registerClass:[Login2FATipCell class] forCellReuseIdentifier:kCellIdentifier_Login2FATipCell];
66-
[tableView registerNib:[UINib nibWithNibName:kCellIdentifier_Input_OnlyText_Cell bundle:[NSBundle mainBundle]] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell];
66+
[tableView registerClass:[Input_OnlyText_Cell class] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell_Text];
67+
[tableView registerClass:[Input_OnlyText_Cell class] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell_Captcha];
6768

6869
tableView.backgroundView = self.bgBlurredView;
6970
tableView.dataSource = self;
@@ -207,39 +208,41 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
207208
return cell;
208209
}
209210

210-
Input_OnlyText_Cell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_Input_OnlyText_Cell forIndexPath:indexPath];
211+
Input_OnlyText_Cell *cell = [tableView dequeueReusableCellWithIdentifier:(indexPath.row > 1? kCellIdentifier_Input_OnlyText_Cell_Captcha: kCellIdentifier_Input_OnlyText_Cell_Text) forIndexPath:indexPath];
211212
cell.isForLoginVC = YES;
212213

213214
__weak typeof(self) weakSelf = self;
214215
if (self.is2FAUI) {
215216
cell.textField.keyboardType = UIKeyboardTypeNumberPad;
216-
[cell configWithPlaceholder:@" 动态验证码" andValue:self.otpCode];
217+
[cell setPlaceholder:@" 动态验证码" value:self.otpCode];
217218
cell.textValueChangedBlock = ^(NSString *valueStr){
218219
weakSelf.otpCode = valueStr;
219220
};
220221
}else{
221222
if (indexPath.row == 0) {
222223
cell.textField.keyboardType = UIKeyboardTypeEmailAddress;
223-
[cell configWithPlaceholder:@" 手机号码/电子邮箱/个性后缀" andValue:self.myLogin.email];
224+
[cell setPlaceholder:@" 手机号码/电子邮箱/个性后缀" value:self.myLogin.email];
224225
cell.textValueChangedBlock = ^(NSString *valueStr){
225226
weakSelf.inputTipsView.valueStr = valueStr;
226227
weakSelf.inputTipsView.active = YES;
227228
weakSelf.myLogin.email = valueStr;
228-
[weakSelf.iconUserView setImage:[UIImage imageNamed:@"icon_user_monkey"]];
229+
[weakSelf refreshIconUserImage];
230+
};
231+
cell.editDidBeginBlock = ^(NSString *valueStr){
232+
weakSelf.inputTipsView.valueStr = valueStr;
233+
weakSelf.inputTipsView.active = YES;
229234
};
230235
cell.editDidEndBlock = ^(NSString *textStr){
231236
weakSelf.inputTipsView.active = NO;
232-
[weakSelf refreshIconUserImage];
233237
};
234238
}else if (indexPath.row == 1){
235-
[cell configWithPlaceholder:@" 密码" andValue:self.myLogin.password];
239+
[cell setPlaceholder:@" 密码" value:self.myLogin.password];
236240
cell.textField.secureTextEntry = YES;
237241
cell.textValueChangedBlock = ^(NSString *valueStr){
238242
weakSelf.myLogin.password = valueStr;
239243
};
240244
}else{
241-
cell.isCaptcha = YES;
242-
[cell configWithPlaceholder:@" 验证码" andValue:self.myLogin.j_captcha];
245+
[cell setPlaceholder:@" 验证码" value:self.myLogin.j_captcha];
243246
cell.textValueChangedBlock = ^(NSString *valueStr){
244247
weakSelf.myLogin.j_captcha = valueStr;
245248
};
@@ -254,8 +257,10 @@ - (void)refreshIconUserImage{
254257
User *curUser = [Login userWithGlobaykeyOrEmail:textStr];
255258
if (curUser && curUser.avatar) {
256259
[self.iconUserView sd_setImageWithURL:[curUser.avatar urlImageWithCodePathResizeToView:self.iconUserView] placeholderImage:[UIImage imageNamed:@"icon_user_monkey"]];
260+
return;
257261
}
258262
}
263+
[self.iconUserView setImage:[UIImage imageNamed:@"icon_user_monkey"]];
259264
}
260265

261266
#pragma mark - Table view Header Footer

Coding_iOS/Controllers/Login/PasswordViewController.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ - (void)viewDidLoad
3434
// 添加myTableView
3535
_myTableView = ({
3636
TPKeyboardAvoidingTableView *tableView = [[TPKeyboardAvoidingTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
37-
[tableView registerNib:[UINib nibWithNibName:kCellIdentifier_Input_OnlyText_Cell bundle:[NSBundle mainBundle]] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell];
37+
[tableView registerClass:[Input_OnlyText_Cell class] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell_Text];
3838
tableView.backgroundColor = kColorTableSectionBg;
3939
tableView.dataSource = self;
4040
tableView.delegate = self;
@@ -105,24 +105,24 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
105105

106106
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
107107
{
108-
Input_OnlyText_Cell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_Input_OnlyText_Cell forIndexPath:indexPath];
108+
Input_OnlyText_Cell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_Input_OnlyText_Cell_Text forIndexPath:indexPath];
109109

110110
__weak typeof(self) weakSelf = self;
111111
if (indexPath.row == 0) {
112112
cell.textField.keyboardType = UIKeyboardTypeEmailAddress;
113-
[cell configWithPlaceholder:@" 电子邮箱" andValue:self.email];
113+
[cell setPlaceholder:@" 电子邮箱" value:self.email];
114114
cell.textField.userInteractionEnabled = NO;
115115
cell.textValueChangedBlock = ^(NSString *valueStr){
116116
weakSelf.email = valueStr;
117117
};
118118
}else if (indexPath.row == 1) {
119-
[cell configWithPlaceholder:@" 密码" andValue:self.password];
119+
[cell setPlaceholder:@" 密码" value:self.password];
120120
cell.textField.secureTextEntry = YES;
121121
cell.textValueChangedBlock = ^(NSString *valueStr){
122122
weakSelf.password = valueStr;
123123
};
124124
}else{
125-
[cell configWithPlaceholder:@" 确认密码" andValue:self.confirm_password];
125+
[cell setPlaceholder:@" 确认密码" value:self.confirm_password];
126126
cell.textField.secureTextEntry = YES;
127127
cell.textValueChangedBlock = ^(NSString *valueStr){
128128
weakSelf.confirm_password = valueStr;

Coding_iOS/Controllers/Login/RegisterViewController.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ - (void)viewDidLoad
4040
// 添加myTableView
4141
_myTableView = ({
4242
TPKeyboardAvoidingTableView *tableView = [[TPKeyboardAvoidingTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
43-
[tableView registerNib:[UINib nibWithNibName:kCellIdentifier_Input_OnlyText_Cell bundle:[NSBundle mainBundle]] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell];
43+
[tableView registerClass:[Input_OnlyText_Cell class] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell_Text];
44+
[tableView registerClass:[Input_OnlyText_Cell class] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell_Captcha];
4445
tableView.backgroundColor = kColorTableSectionBg;
4546
tableView.dataSource = self;
4647
tableView.delegate = self;
@@ -119,12 +120,12 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
119120

120121
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
121122
{
122-
Input_OnlyText_Cell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_Input_OnlyText_Cell forIndexPath:indexPath];
123+
Input_OnlyText_Cell *cell = [tableView dequeueReusableCellWithIdentifier:(indexPath.row > 1? kCellIdentifier_Input_OnlyText_Cell_Captcha: kCellIdentifier_Input_OnlyText_Cell_Text) forIndexPath:indexPath];
123124

124125
__weak typeof(self) weakSelf = self;
125126
if (indexPath.row == 0) {
126127
cell.textField.keyboardType = UIKeyboardTypeEmailAddress;
127-
[cell configWithPlaceholder:@" 电子邮箱" andValue:self.myRegister.email];
128+
[cell setPlaceholder:@" 电子邮箱" value:self.myRegister.email];
128129
cell.textValueChangedBlock = ^(NSString *valueStr){
129130
weakSelf.inputTipsView.valueStr = valueStr;
130131
weakSelf.inputTipsView.active = YES;
@@ -134,13 +135,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
134135
weakSelf.inputTipsView.active = NO;
135136
};
136137
}else if (indexPath.row == 1){
137-
[cell configWithPlaceholder:@" 个性后缀" andValue:self.myRegister.global_key];
138+
[cell setPlaceholder:@" 个性后缀" value:self.myRegister.global_key];
138139
cell.textValueChangedBlock = ^(NSString *valueStr){
139140
weakSelf.myRegister.global_key = valueStr;
140141
};
141142
}else{
142-
cell.isCaptcha = YES;
143-
[cell configWithPlaceholder:@" 验证码" andValue:self.myRegister.j_captcha];
143+
[cell setPlaceholder:@" 验证码" value:self.myRegister.j_captcha];
144144
cell.textValueChangedBlock = ^(NSString *valueStr){
145145
weakSelf.myRegister.j_captcha = valueStr;
146146
};

Coding_iOS/Images.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@
113113
"idiom" : "ipad",
114114
"filename" : "152x152.png",
115115
"scale" : "2x"
116+
},
117+
{
118+
"idiom" : "ipad",
119+
"size" : "83.5x83.5",
120+
"scale" : "2x"
116121
}
117122
],
118123
"info" : {

Coding_iOS/Util/OC_Category/UIButton+Common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@
2626

2727
+ (UIButton *)tweetBtnWithFrame:(CGRect)frame alignmentLeft:(BOOL)alignmentLeft;
2828
- (void)animateToImage:(NSString *)imageName;
29+
30+
//开始请求时,UIActivityIndicatorView 提示
31+
- (void)startQueryAnimate;
32+
- (void)stopQueryAnimate;
33+
2934
@end

Coding_iOS/Util/OC_Category/UIButton+Common.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#import <POP+MCAnimate/POP+MCAnimate.h>
1212
#import <math.h>
1313

14+
@interface UIButton ()
15+
@property (strong, nonatomic) UIActivityIndicatorView *activityIndicator;
16+
@end
17+
1418
@implementation UIButton (Common)
1519
+ (UIButton *)buttonWithTitle:(NSString *)title titleColor:(UIColor *)color{
1620
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
@@ -180,4 +184,31 @@ - (void)animateToImage:(NSString *)imageName{
180184
[imageV pop_addAnimation:moveA forKey:@"animateToImage"];
181185
}
182186
}
187+
#pragma mark -
188+
//开始请求时,UIActivityIndicatorView 提示
189+
static char EAActivityIndicatorKey;
190+
- (void)setActivityIndicator:(UIActivityIndicatorView *)activityIndicator{
191+
objc_setAssociatedObject(self, &EAActivityIndicatorKey, activityIndicator, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
192+
193+
}
194+
- (UIActivityIndicatorView *)activityIndicator{
195+
return objc_getAssociatedObject(self, &EAActivityIndicatorKey);
196+
}
197+
198+
- (void)startQueryAnimate{
199+
if (!self.activityIndicator) {
200+
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
201+
self.activityIndicator.hidesWhenStopped = YES;
202+
[self addSubview:self.activityIndicator];
203+
[self.activityIndicator mas_makeConstraints:^(MASConstraintMaker *make) {
204+
make.center.equalTo(self);
205+
}];
206+
}
207+
[self.activityIndicator startAnimating];
208+
self.enabled = NO;
209+
}
210+
- (void)stopQueryAnimate{
211+
[self.activityIndicator stopAnimating];
212+
self.enabled = YES;
213+
}
183214
@end

0 commit comments

Comments
 (0)