要设置UIPickerView选中行的遮罩颜色,可以使用UIPickerViewDelegate中的方法pickerView:viewForRow:forComponent:reusingView:来自定义选中行的视图,并在该方法中设置选中行的背景颜色。

以下是一个示例代码,演示如何设置选中行的遮罩颜色为红色:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
    UILabel *label = (UILabel *)view;
    if (label == nil) {
        label = [[UILabel alloc] init];
        label.textAlignment = NSTextAlignmentCenter;
    }
    
    // 设置选中行的背景颜色为红色
    if (row == [pickerView selectedRowInComponent:component]) {
        label.backgroundColor = [UIColor redColor];
    } else {
        label.backgroundColor = [UIColor clearColor];
    }
    
    // 设置其他行的背景颜色为白色
    if (component == 0) {
        label.text = [NSString stringWithFormat:@"%ld", (long)row];
    } else {
        label.text = [NSString stringWithFormat:@"%ld", (long)row+10];
    }
    
    return label;
}

在上述代码中,我们根据选中行的索引来设置背景颜色。如果当前行为选中行,则将背景颜色设置为红色,否则将背景颜色设置为透明。你可以根据需要修改选中行的背景颜色和其他行的背景颜色

UIPickerView 选中的遮罩设置颜色OC代码

原文地址: http://www.cveoy.top/t/topic/iiIM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录