要设置UIPickerView选中行的遮罩颜色,可以使用UIPickerViewDelegate中的方法pickerView:viewForRow:forComponent:reusingView:来自定义选中行的视图,并在该方法中设置选中行的背景颜色。\n\n以下是一个示例代码,演示如何设置选中行的遮罩颜色为红色:\n\nobjective-c\n- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {\n UILabel *label = (UILabel *)view;\n if (label == nil) {\n label = [[UILabel alloc] init];\n label.textAlignment = NSTextAlignmentCenter;\n }\n \n // 设置选中行的背景颜色为红色\n if (row == [pickerView selectedRowInComponent:component]) {\n label.backgroundColor = [UIColor redColor];\n } else {\n label.backgroundColor = [UIColor clearColor];\n }\n \n // 设置其他行的背景颜色为白色\n if (component == 0) {\n label.text = [NSString stringWithFormat:@'%ld', (long)row];\n } else {\n label.text = [NSString stringWithFormat:@'%ld', (long)row+10];\n }\n \n return label;\n}\n\n\n在上述代码中,我们根据选中行的索引来设置背景颜色。如果当前行为选中行,则将背景颜色设置为红色,否则将背景颜色设置为透明。你可以根据需要修改选中行的背景颜色和其他行的背景颜色。

UIPickerView 选中行遮罩颜色设置 -  Objective-C 代码示例

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

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