Skip to content

Instantly share code, notes, and snippets.

@joelbrewer
Last active December 18, 2015 17:54
Show Gist options
  • Save joelbrewer/94c1eed7d872d765a93c to your computer and use it in GitHub Desktop.
Save joelbrewer/94c1eed7d872d765a93c to your computer and use it in GitHub Desktop.
attributedTitleForRow
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *title = [[self.items objectAtIndex:row] objectForKey:@"text"];
NSString *color = [[self.items objectAtIndex:row] objectForKey:@"color"];
NSAttributedString *attrStr;
if ([ color isEqualToString:@"green"]) {
attrStr = [[NSAttributedString alloc] initWithString:title attributes:@{ NSForegroundColorAttributeName : [UIColor greenColor] }];
} else {
attrStr = [[NSAttributedString alloc] initWithString:title attributes:@{ NSForegroundColorAttributeName : [UIColor blackColor] }];
}
return attrStr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment