0

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.

Community
  • 1
  • 1
Armand
  • 3
  • 1
  • 2
    `pickerView:attributedTitleForRow:forComponent:` is the delegate method defined by the protocol -- it must be named exactly like that (like in the answer you linked to). Additionally, you're not supposed to call it yourself -- the picker view will call it (as long as it's named right). –  Jul 22 '14 at 02:51
  • Try like this, http://stackoverflow.com/questions/18807940/can-i-change-the-font-color-of-the-datepicker-in-ios7 This may help you – Iphonenew Jul 22 '14 at 04:14

1 Answers1

1
  • Alternatively you may use the below delegate also and define a UILabel to set your preferred color for the text

    – pickerView:viewForRow:forComponent:reusingView:
    
raja
  • 1,151
  • 7
  • 9