Reputation: 3444
Does anyone know if it is possible to change the font and/or color for individual UIPickerView Items?
Upvotes: 14
Views: 9464
Reputation: 870
For this, I would simply go with attributed strings.
Implement this method is your delegate:
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView
attributedTitleForRow:(NSInteger)row
forComponent:(NSInteger)component
Upvotes: 0
Reputation: 3666
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel* tView = (UILabel*)view;
if (!tView){
tView = [[UILabel alloc] init];
// Setup label properties - frame, font, colors etc
...
}
// Fill the label text here
...
return tView;
}
Upvotes: 36
Reputation: 170839
Yes, it is possible. To do that you need to implement pickerView:viewForRow:forComponent:reusingView:
method in picker's delegate - create UILabel
instance there and setup it with whatever attributes you want.
Upvotes: 20