iOS开发---冷门小技巧

1.iOS 7后隐藏UITextField的光标

 

    通常我们用UIPickerView作为我们的UITextField的inputView时,我们是需要隐藏光标的。当然,如果想换个光标颜色,也是这么处理。

1 textFiled.tintColor = [UIColor clearColor];

    这么处理的有个遗留问题是:通常我们使用UIPickerView作为UITextField的inputView时, 并不希望去执行各种菜单操作(全选、复制、粘帖),但只是去设置UITextField的tintColor时,我们仍然可以执行这边操作,所以需要加额外的处理。这个问题,我们可以这样处理:在textFieldShouldBeginEditing:中,我们把UITextField的userInteractionEnabled设置为NO,然后在textFieldShouldEndEditing:,将将这个值设置回来。如下:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    textField.userInteractionEnabled = NO;
    return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    textField.userInteractionEnabled = YES;
    return YES;
}

 

 2.限制 textField 输入字数

  if (textField == textfield_withdraw_depostis) {

        NSInteger strLength = textField.text.length - range.length + string.length;

        return (strLength < 7);

    }

3.限制选择器的时间选择

 

    /** 设置可以选择的最大时间  为当前时间 减一天*/

    NSDate* date = [[NSDate alloc] init];

//    date = [date dateByAddingTimeInterval:-1*3600*24];

    NSDate *mumDate = date;

    datePicker.minimumDate = mumDate;

 

4,防止用户多次点击按钮.

 

- (void)todoSomething:(id)sender

{

    //在这里做按钮的想做的事情。

}

 

- (void)starButtonClicked:(id)sender

{

    //先将未到时间执行前的任务取消。

    [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(todoSomething:) object:sender];

    [self performSelector:@selector(todoSomething:) withObject:sender afterDelay:0.2f];

}

 

对于第二种方法,快速点击N次,只要每次间隔在0.2秒内的都不响应操作,等到停下点击到达0.2秒后再执行。所以按照自己的需要设置响应时间,狂点吧。只响应一次。。

 

posted @ 2015-06-15 11:30  iOS-轻狂书生  阅读(215)  评论(0编辑  收藏  举报