zoukankan      html  css  js  c++  java
  • iOS----------输入框UITextField禁止输入空格

    方法一:添加代理

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

    {

        NSString *tem = [[string componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]componentsJoinedByString:@""];

        if (![string isEqualToString:tem]) {

            return NO;

        }

        return YES;

    }

    方法二:

        [self.searchTextField addTarget:self action:@selector(searchTextFieldChange:) forControlEvents:UIControlEventEditingChanged];

    在searchTextFieldChange方法中   直接替换空的字符串

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

     textField.text =[textField.text stringByReplacingOccurrencesOfString:@" " withString:@""];

     }

  • 相关阅读:
    自定义checkbox样式
    自定义select样式
    jsonp
    I/O复用 poll简介
    DOS和DDOS攻击
    TCP状态转换图解析
    Makefile入门
    I/O复用select 使用简介
    替换文本内容
    share memory
  • 原文地址:https://www.cnblogs.com/KiVen2015/p/8063859.html
Copyright © 2011-2022 走看看