Ios PickerView为行生成单独的颜色
所以我想要的是在PickerView中为我的行制作单独的颜色,但我真的不知道如何做到这一点。知道如何制作个性化的文本颜色也很酷。Ios PickerView为行生成单独的颜色,ios,text,colors,uipickerview,uicolor,Ios,Text,Colors,Uipickerview,Uicolor,所以我想要的是在PickerView中为我的行制作单独的颜色,但我真的不知道如何做到这一点。知道如何制作个性化的文本颜色也很酷。 谢谢。因此,如果您正在检查UIPickerView数据源,您将发现以下方法: - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view; 我想您可以使用
谢谢。因此,如果您正在检查
UIPickerView数据源
,您将发现以下方法:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;
我想您可以使用它来修改pickerView
中的视图,方法如下:
- 启动您的
pickerView
视图中加载
,例如:
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height / 4, self.view.frame.size.width, self.view.frame.size.height / 2)];
pickerView.delegate = self;
pickerView.dataSource = self;
[self.view addSubview:pickerView];
- 调用所需的方法并进行更改:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UIView *customRow = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
switch (row) {
case 0:
customRow.backgroundColor = [UIColor redColor];
return customRow;
break;
case 1:
customRow.backgroundColor = [UIColor orangeColor];
return customRow;
case 2:
customRow.backgroundColor = [UIColor yellowColor];
return customRow;
case 3:
customRow.backgroundColor = [UIColor greenColor];
return customRow;
case 4:
customRow.backgroundColor = [UIColor blueColor];
return customRow;
case 5:
customRow.backgroundColor = [UIColor purpleColor];
return customRow;
default:
return nil;
break;
}
}
- 不要忘记实现中所需的方法:
#pragma mark: UIPickeView datasource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return 6;
}
到目前为止你试过什么吗?如果是,你试过什么?