|
//
// editSignController.m
// ThePaperHD
//
// Created by scar1900 on 15/3/29.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "editSignController.h"
#define TEXTFIELDTAG 2000
@interface editSignController () {
NSString *signStr;
}
@end
@implementation editSignController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.titleLabel.text = @"修改签名";
self.editRangeLabel.text = @"请输入4-30个字符";
self.editNameField.text = [TPUserDefault instance].userBO.perDesc;
signStr = [TPUserDefault instance].userBO.perDesc;
NSAttributedString* atrString = [[NSAttributedString alloc] initWithString:@"请输入签名" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:LINECOLOR]}];
self.editNameField.attributedPlaceholder = atrString;
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(editChange:)
name:UITextFieldTextDidChangeNotification
object:self.editNameField];
}
- (void)confirmEvent:(UIButton*)btn {
[self closeKeyBoard];
signStr = self.editNameField.text;
if (isBlankString(signStr)) {
ShowTextMessage(@"请输入签名");
return;
}
NSDictionary *dic = @{@"perDesc":signStr};
__weak typeof(self) Self = self;
[Remote doJsonActionWithBlock:0 requestUrl:editUserInfoURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
userBO *user = setJsonDicToDataModel(responseData[@"userInfo"], [userBO class]);
userBO *oriUser = [TPUserDefault instance].userBO;
user.loginType = oriUser.loginType;
[TPUserDefault instance].userBO = user;
[(MLNavigationController*)Self.navigationController popViewControllerWithFlip];
}else {
ShowTextMessage(message);
}
}];
}
//- (void)textFieldDidChange:(UITextField *)textField {
// if (textField == self.editNameField) {//【需求】昵称、签名超过字符就不再输入(bug:4087
// if (textField.text.length >30) {
// textField.text= [textField.text substringToIndex:30];
// }
// }
// signStr = textField.text;
//}
-(void) editChange:(NSNotification*) obj{
UITextField *textField = (UITextField *)obj.object;
NSString *toBeString = textField.text;
NSString *lang = [[UITextInputMode currentInputMode] primaryLanguage]; // 键盘输入模式
if ([lang isEqualToString:@"zh-Hans"]) { // 简体中文输入,包括简体拼音,健体五笔,简体手写
UITextRange *selectedRange = [textField markedTextRange];
//获取高亮部分
UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
// 没有高亮选择的字,则对已输入的文字进行字数统计和限制
if (!position) {
if (toBeString.length > 30) {
textField.text = [toBeString substringToIndex:30];
}
}
// 有高亮选择的字符串,则暂不对文字进行统计和限制
else{
}
}
// 中文输入法以外的直接对其统计限制即可,不考虑其他语种情况
else{
if (toBeString.length > 15) {
textField.text = [toBeString substringToIndex:15];
}
}
}
- (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
|