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"]