Reputation: 3
I have a UIPickerView and I would like to change the color of the text to white according to the method shown in this stack overflow question: How do I change the color of the text in a UIPickerView under iOS 7? .
However, the code that I typed does not seem to work. Can someone please tell me why?
I have the following method in my ViewController.m
- (NSAttributedString *)changePickerColor:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component :(NSString*)title
{
NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
return attString;
}
And in my viewDidLoad I this code:
self.instruments = [[NSMutableArray alloc]initWithObjects:@"Baritone",@"Trumpet",@"French Horn",@"Tuba", nil];
for (int i = 0; i < self.instruments.count; i++) {
[self changePickerColor:self.pickerView attributedTitleForRow:i forComponent:0 :self.instruments[i]];
}
I am not receiving any error messages, the code simply just does not work. Please Help, Thank You.
Upvotes: 0
Views: 951
Reputation: 1161
Alternatively you may use the below delegate also and define a UILabel to set your preferred color for the text
– pickerView:viewForRow:forComponent:reusingView:
Upvotes: 1