iOS清除UIDatePicker和UIPickerView中间Row上面的分割线

在iOS目前的官方API里面,还没有清除UIDatePicker和UIPickerView的方法,这里介绍2种方法做到这一点

第一种方案就是贴UIImageView,对,贴上上线条去遮盖这系统原有的分割线,这种方法笨,但是实用。

第二种方案是便利UIDatePicker和UIPickerView上面的所有View,并且设置row上面的View为透明的,这种方法也是本文介绍的重点,具体代码如下:

- (void)clearSeparatorWithView:(UIView * )view
{
    if(view.subviews != 0  )
    {
        if(view.bounds.size.height < 5)
        {
            view.backgroundColor = [UIColor clearColor];
        }
        
        [view.subviews enumerateObjectsUsingBlock:^( UIView *  obj, NSUInteger idx, BOOL *  stop) {
            [self clearSeparatorWithView:obj];
        }];
    }
    
}

调用方法就页很简单,下面以UIDatePicker为例,代码如下:

    // date picker
    self.birthdayPV=[[UIDatePicker alloc]initWithFrame:baseView.frame];
    [self.birthdayPV addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
    self.birthdayPV.datePickerMode=UIDatePickerModeDate;
//调用如下方法清除row的分割线
    [self clearSeparatorWithView:self.birthdayPV];
清除前的效果图如下:

iOS清除UIDatePicker和UIPickerView中间Row上面的分割线_第1张图片


清除分割线之后的效果图如下:

iOS清除UIDatePicker和UIPickerView中间Row上面的分割线_第2张图片


如果对你的开发有帮助,请点个赞!



你可能感兴趣的:(iOS清除UIDatePicker和UIPickerView中间Row上面的分割线)