美文网首页
iOS UITextField 只允许输入特定文字

iOS UITextField 只允许输入特定文字

作者: 龍飝 | 来源:发表于2018-08-23 09:11 被阅读35次
  • (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

    NSCharacterSet *characterSet = [[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFJHIGKLMNOPQRSTUVWXYZ1234567890"] invertedSet];
    NSString *filtered = [[string componentsSeparatedByCharactersInSet:characterSet] componentsJoinedByString:@""];
    return [string isEqualToString:filtered];

}

相关文章

网友评论

      本文标题:iOS UITextField 只允许输入特定文字

      本文链接:https://www.haomeiwen.com/subject/buqpiftx.html