我想更改uipickerview选择所在行的颜色。还有另一个问题,但唯一的答案是展示如何将uipickerview中的所有文本更改为某种颜色。我只是希望在查看器中选择的文本显示不同的颜色。
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent: (NSInteger) component reusingView:(UIView *)view
{
NSString *rowItem =[thing objectAtIndex:row];
UILabel *lblRow = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [pickerView bounds].size.width, 44.0f];
[lblRow setTextColor: [UIColor grayColor]];
[lblRow setTextAlignment:NSTextAlignmentCenter];
[lblRow setText:rowItem];
[lblRow setBackgroundColor:[UIColor clearColor];
return lblRow;
}
答案 0 :(得分:0)
如何使用此委托方法:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSString *rowItem =[thing objectAtIndex:row];
UILabel *lblRow = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [pickerView bounds].size.width, 44.0f];
[lblRow setTextColor: [UIColor grayColor]];
[lblRow setTextAlignment:NSTextAlignmentCenter];
[lblRow setText:rowItem];
[lblRow setBackgroundColor:[UIColor clearColor];
}