问题
I want to change the color of the row that the selection of the uipickerview lands on. There is another question like this but the only answer is showing how to make all the text in the uipickerview changed to a certain color. I just want the text when selected in the viewer to appear a different color.
-(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;
}
回答1:
How about using this delegate method instead:
- (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];
}
来源:https://stackoverflow.com/questions/22649740/how-to-change-text-color-when-selected-in-uipickerview