UITextField
#PRagma mark - UITextFieldDelegate- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ if(textField == self.nameTextField){ UITextRange *selectedRange = [textField markedTextRange]; UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0]; if(position && (range.length==0 || string.length==0)){ return YES; }else{ NSString *str = [textField.text stringByReplacingCharactersInRange:NSMakeRange(range.location, range.length) withString:string]; if(str.length>30){//限制字数,多余截断 self.nameTextField.text = [str substringToIndex:30]; [self.dict setObject:self.nameTextField.text forKey:@"name"]//保存到dict中 if(self.guestParamEdit){ self.guestParamEdit(self.dict, self); } return NO; }else{//保存到dict中 [self.dict setObject:str forKey:@"name"]; if(self.guestParamEdit){ self.guestParamEdit(self.dict, self); } } } } return YES;}
新闻热点
疑难解答