// // editSignController.m // ThePaperBase // // Created by Huixin on 15/8/26. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "editSignController.h" @interface editSignController () @property(nonatomic, strong)UITextField *signField; @property(nonatomic, strong)UIView *lineView; @property(nonatomic, strong)UILabel *textRangeLabel; @property(nonatomic, strong)TPCustomButton *confirmButton; @end @implementation editSignController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.titleStr =@"修改签名"; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)]; [self.view addGestureRecognizer:tapGesture]; [self.view addSubview:self.signField]; [self.view addSubview:self.lineView]; [self.view addSubview:self.textRangeLabel]; [self.view addSubview:self.confirmButton]; [self.signField becomeFirstResponder]; [self layoutViews]; } - (void)layoutViews { [self.signField makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.naviBar.bottom).offset(36); make.left.equalTo(self.view.left).offset(20); make.right.equalTo(self.view.right).offset(-20); make.height.mas_equalTo(@19); }]; [self.lineView makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.signField.bottom).offset(6); make.left.equalTo(self.signField.left); make.right.equalTo(self.signField.right); make.height.mas_equalTo(@1); }]; [self.textRangeLabel makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.lineView.bottom).offset(4); make.left.equalTo(self.signField.left); make.right.equalTo(self.signField.right); make.height.mas_equalTo(@12); }]; [self.confirmButton makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.textRangeLabel.bottom).offset(45); make.left.equalTo(self.signField.left); make.right.equalTo(self.signField.right); make.height.equalTo(self.confirmButton.width).multipliedBy(0.15); }]; } - (UITextField*)signField { if (!_signField) { _signField = [[UITextField alloc] init]; _signField.backgroundColor = [UIColor clearColor]; _signField.textAlignment = NSTextAlignmentLeft; _signField.textColor = [UIColor colorWithHexString:TextBlack]; _signField.keyboardAppearance = UIKeyboardAppearanceDefault; if ([[TPUserDefault instance].isNightMode intValue] > 0) { _signField.keyboardAppearance = UIKeyboardAppearanceDark; } _signField.keyboardType = UIKeyboardTypeDefault; _signField.clearButtonMode = UITextFieldViewModeWhileEditing; NSAttributedString* atrString = [[NSAttributedString alloc] initWithString:@"请输入签名" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:TextLightGray]}]; _signField.attributedPlaceholder = atrString; _signField.delegate = self; [_signField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; _signField.returnKeyType = UIReturnKeyDone; } _signField.font = appFont(TEXT_FOUR_LEVELSIZE, NO); return _signField; } - (UIView*)lineView { if (!_lineView) { _lineView = [[UIView alloc] init]; _lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _lineView; } - (UILabel*)textRangeLabel { if(!_textRangeLabel) { _textRangeLabel = [[UILabel alloc] init]; _textRangeLabel.backgroundColor = [UIColor clearColor]; _textRangeLabel.textAlignment = NSTextAlignmentRight; _textRangeLabel.textColor = [UIColor colorWithHexString:TextLightGray]; _textRangeLabel.text = @"请输入4-30个字符"; } _textRangeLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO); return _textRangeLabel; } - (TPCustomButton*)confirmButton { if (!_confirmButton) { _confirmButton = [[TPCustomButton alloc] init]; _confirmButton.title = @"确认"; [_confirmButton addTarget:self action:@selector(confirm) forControlEvents:UIControlEventTouchUpInside]; } return _confirmButton; } - (void)setOriginStr:(NSString *)originStr { _originStr = originStr; self.signField.text = originStr; } #pragma mark - button event handler - (void)confirm { [self closeKeyBoard]; if (isBlankString(self.originStr)) { ShowTextMessage(@"请输入签名"); return; } NSDictionary *dic = @{@"perDesc":self.originStr}; [Remote doJsonAction:0 requestUrl:editUserInfoURL parameter:dic delegate:self]; } #pragma mark - textfield delegate - (void)textFieldDidChange:(UITextField *)textField { if ([textField.text isMatchedByRegex:@"[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]"]) { textField.text = disable_emoji(textField.text); } //bug5103: 处理输入法表情图片 _originStr = textField.text; } - (BOOL)textFieldShouldReturn:(UITextField *)textField { if (textField == _signField) { [self confirm]; } return YES; } - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { //bug5103: 处理输入法表情图片 if ([textField isFirstResponder]) { if ([[[textField textInputMode] primaryLanguage] isEqualToString:@"emoji"] || ![[textField textInputMode] primaryLanguage]) { return NO; } } return YES; } #pragma mark - remote delegate - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responseData { if (actionTag == 0) { userBO *user = setJsonDicToDataModel(responseData[@"userInfo"], [userBO class]); NSString *lastLoginType = [TPUserDefault instance].userBO.loginType; user.loginType = lastLoginType; [TPUserDefault instance].userBO = user; [self.navigationController popViewControllerAnimated:YES]; } } - (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code{ ShowTextMessage(message); } #pragma mark - tap handler - (void)tap:(id)sender { [self closeKeyBoard]; } #pragma mark - keyBoard event - (void)closeKeyBoard { [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end