IT虾米网

限制 UITextField 的输入长度

shasha 2018年06月23日 手机开发 955 0
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range  
                            replacementString:(NSString *)string  
{ 
    //Check that response should be a maximum 5 characters 
    if ([string length] > 0) { 
        return [textField.text length] < 5; 
    } 
    return YES; 
} 
 
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 
{ 
    if([string length]>0{ 
        return [textField.text length]<5;  //这里报错,textField没有 text属性? 
    } 
       return YES; 
}

评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!