IVTEditMySignatureViewController.m
4.65 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// IVTEditMySignatureViewController.m
// IVTMeLiveTwo
//
// Created by XRG on 16/8/24.
// Copyright © 2016年 QLQ. All rights reserved.
//
#import "IVTEditMySignatureViewController.h"
@interface IVTEditMySignatureViewController ()
{
UITextView *signTextView;
UILabel *numLable;
UILabel *remineLable;
NSString *textString;
}
@end
@implementation IVTEditMySignatureViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setNavigationBar];
signTextView = [[UITextView alloc]initWithFrame:CGRectMake(0, 5, kScreenWidth, 92)];
signTextView.font = [UIFont IVTH3Font];
signTextView.textColor = [UIColor IVTMainTextColor];
signTextView.returnKeyType = UIReturnKeyDone;
signTextView.clearsOnInsertion = YES;
signTextView.autocorrectionType = UITextAutocorrectionTypeNo;//不联想输入
signTextView.autocapitalizationType = UITextAutocapitalizationTypeNone;//不大小写
signTextView.text = [[IVTAccountTool getSignature] base64DecodedToString];
[self.view addSubview:signTextView];
[signTextView becomeFirstResponder];
textString = signTextView.text;
CGFloat x = signTextView.bounds.size.width-25;
CGFloat y = signTextView.bounds.size.height-25;
numLable = [[UILabel alloc]initWithFrame:CGRectMake(x, y, 20, 20)];
numLable.text = @"32";
numLable.textColor = [UIColor IVTAssistColor];
numLable.font = [UIFont YXFontOfSize:14];
[signTextView addSubview:numLable];
remineLable = [[UILabel alloc]init];
remineLable.frame = CGRectMake(0, 115, kScreenWidth, 20);
remineLable.textAlignment = NSTextAlignmentCenter;
remineLable.text = @"您最多还能输入32个字";
remineLable.textColor = [UIColor IVTAssistColor];
remineLable.font = [UIFont YXFontOfSize:14];
[self.view addSubview:remineLable];
numLable.text = [NSString stringWithFormat:@"%ld",32-signTextView.text.length];
remineLable.text = [NSString stringWithFormat:@"您最多还能输入%ld个字",32-signTextView.text.length];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidChange:) name:UITextViewTextDidChangeNotification object:nil];
}
- (void)setNavigationBar{
self.navigationItem.title = @"个性签名";
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(doSave:)];
rightBarButton.tintColor = [UIColor whiteColor];
self.navigationItem.rightBarButtonItem = rightBarButton;
}
- (void)textFieldDidChange:(NSNotification *)notification{
if (signTextView.text.length > 32) {
signTextView.text = textString;
}
else{
textString = signTextView.text;
numLable.text = [NSString stringWithFormat:@"%ld",32-signTextView.text.length];
remineLable.text = [NSString stringWithFormat:@"您最多还能输入%ld个字",32-signTextView.text.length];
}
}
- (void)doSave:(UIBarButtonItem *)barBtnItem{
if (signTextView.text.length > 0) {
barBtnItem.enabled = NO;
[HUDUtil showLoading];
[[IVTNetworkAPIClient sharedClient] modifySignature:[signTextView.text base64EncodedFromString] success:^(NSDictionary *successData) {
[IVTAccountTool setSignature:[signTextView.text base64EncodedFromString]];
[[NSNotificationCenter defaultCenter] postNotificationName:@"successToChangeSignature" object:nil];
if (self.editSuccessBlock) {
self.editSuccessBlock(signTextView.text);
}
[HUDUtil showSuccess:@"修改成功"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.navigationController popViewControllerAnimated:YES];
});
} error:^(NSDictionary *successData) {
NSString *msg = successData[@"description"];
[HUDUtil showError:msg];
barBtnItem.enabled = YES;
} failure:^(NSError *failureError) {
[HUDUtil showError:@"网络异常"];
barBtnItem.enabled = YES;
}];
}
else{
[HUDUtil showError:@"个人签名不能为空"];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end