iOS UItextField去除空格

UItextField 中去除输入的前后空格

1.在结束编辑时去除

- (void)textFieldDidEndEditing:(UITextField *)textField{

    NSString *temp = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

    textField.text = temp;

}

2.

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{  

    NSString *temp = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceCharacterSet]];

    textField.text = temp;

}


你可能感兴趣的:(iOS-基础属性)