2

This might be a silly and really simple question, but I've not been able to solve it.

I have a view controller with a black background onto which I have placed a PickerView control. I have set the delegate and datasource and have confirmed they are working properly.

When I place the same picker view onto a black background, and set the tint to white and the background color to clear, the picker view is invisible. All I am trying to do is have white fonts on a black background, that is, have the picker view visible. The only way I have found to make the picker view visible is to set the background to white, which defeats the design of this app.

Obviously I am missing something, but what? Any suggestions? Thanks!

Pheepster
  • 6,045
  • 6
  • 41
  • 75

2 Answers2

3

In your picker view delegate, instead of supplying titleForRow:, supply attributedTitleForRow: with attributed strings whose color is white.

Alternatively, use viewForRow: and supply UILabels whose font color is white.

matt
  • 515,959
  • 87
  • 875
  • 1,141
3

The tint option will make the background view tinted.

If you want the text to be in white color you should set the text color to white like this (source):

- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component {
    NSString *title = @"sample title";
    NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

return attString;

}
Community
  • 1
  • 1
Nicos Karalis
  • 3,724
  • 4
  • 33
  • 62