user865155
user865155

Reputation:

How to change text color inside uipicker?

How to change the text color inside picker with various colors. For Example: enter image description here

Upvotes: 1

Views: 1836

Answers (2)

Deepesh
Deepesh

Reputation: 8053

Try this:-

 - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
        UILabel *demoLbl = (id)view;
        if (!demoLbl) {
            demoLbl= [[[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [pickerView rowSizeForComponent:component].width, [pickerView rowSizeForComponent:component].height)] autorelease];
        }

        demoLbl.text = @"Demo";
        demoLbl.textColor = [UIColor redColor];
        demoLbl.font = [UIFont systemFontOfSize:14];
        return demoLbl;
    }

Upvotes: 0

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

Use pickerView:viewForRow, and return a UILabel that has the color you want

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    UILabel *label = [[UILabel alloc] init];
    label.text = @"Row";
    label.textColor = [UIColor greenColor];
    return label;
}

Upvotes: 3

Related Questions