1

I had an app about a year and half ago I was fooling with that I decided to come back to it. When I left it the pickerview was visible and worked. Now it still works but the text color is black along with the background. How can I get the text color different with these functions?

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{

    if (component == SIZE)
        return [arraySize count];
    if (component == MEASURE)
        return [arrayMeasure count];
    return 0;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (component == SIZE)
        return [arraySize objectAtIndex:row];
    if (component == MEASURE)
        return [arrayMeasure objectAtIndex:row];
    return 0;
}
narner
  • 2,908
  • 3
  • 26
  • 63
Intelwalk
  • 671
  • 2
  • 13
  • 31

3 Answers3

1

You can just change the color for each label in the picker. See this thread for the answer: can I change the font color of the datePicker in iOS7?

Community
  • 1
  • 1
Mkni1408
  • 125
  • 1
  • 2
  • 9
0

To change the color of the title use:

- (NSAttributedString *)pickerView:(UIPickerView *)pickerView
             attributedTitleForRow:(NSInteger)row
                      forComponent:(NSInteger)component

This lets you provide an attributed string for the title.

Example

- (NSAttributedString *)pickerView:(UIPickerView *)pickerView  
             attributedTitleForRow:(NSInteger)row 
                      forComponent:(NSInteger)component
{
    return [[NSAttributedString alloc] initWithString:@"Your title"              
                                           attributes:@
    {
        NSForegroundColorAttributeName:[UIColor redColor]
    }];
}
Community
  • 1
  • 1
Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
0

Add this method may be help you.

- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    NSAttributedString *attString  = nil;
    NSString *title = @"";

    if (component == SIZE)
        title = [arraySize objectAtIndex:row];
    if (component == MEASURE)
        title = [arrayMeasure objectAtIndex:row];
   attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor greenColor]}];

   return attString;

}
Dipen Chudasama
  • 3,063
  • 21
  • 42