Does anyone know how to change the color of a row (or row background) in the UIPickerView control from the iPhone SDK? Similiar to the below title for row, however I would also
I implemented the following based on Sean's answer:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
CGRect rowFrame = CGRectMake(00.0f, 0.0f, [pickerView viewForRow:row forComponent:component].frame.size.width, [pickerView viewForRow:row forComponent:component].frame.size.height);
UILabel *label = [[UILabel alloc] initWithFrame:rowFrame];
label.font = [UIFont boldSystemFontOfSize:18.0f];
// This is an array I pass to the picker in prepareForSegue:sender:
label.text = [self.values objectAtIndex:row];
label.textAlignment = UITextAlignmentCenter;
// This is an array I pass to the picker in prepareForSegue:sender:
if ([self.backgroundColors count]) {
label.backgroundColor = [self.backgroundColors objectAtIndex:row];
// self.lightColors is an array I instantiate in viewDidLoad: self.lightColors = @[ [UIColor yellowColor], [UIColor greenColor], [UIColor whiteColor] ];
label.textColor = [self.lightColors containsObject:label.backgroundColor] ? [UIColor blackColor] : [UIColor whiteColor];
} else {
label.textColor = [UIColor blackColor];
}
return label;
}