Overriding highlighted selection in UIPickerView

前端 未结 4 1435
别那么骄傲
别那么骄傲 2020-12-03 02:19

I have a custom UIPickerView where I use:

-(UIView *)pickerView:(UIPickerView *)pickerView
       viewForRow:(NSInteger)row
     forComponent:(N         


        
4条回答
  •  情书的邮戳
    2020-12-03 02:33

    I'm not sure if there is an easy way to remove the selection feedback, but you can cover it up if you make the background of the label white and size it to the same dimensions as the blue selection rectangle:

    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
    
        UILabel *pickerRowLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 316, 40)];
        pickerRowLabel.backgroundColor = [UIColor whiteColor];
        pickerRowLabel.text = [pickerDataArray objectAtIndex:row];  
        [self.view addSubview:pickerRowLabel];
    
        return pickerRowLabel;
    
    }
    

    With a width of 316 the label covers all but a sliver of blue on each side, and at 320 it completely covers the selection feedback but it also starts to cover a bit of the outer wheel gradients, which may or may not bother you.

提交回复
热议问题