如何更改uipicker内的文字颜色?

时间:2012-06-29 11:01:40

标签: iphone ios ipad uipickerview uipicker

如何使用各种颜色更改选取器内的文本颜色。例如: enter image description here

2 个答案:

答案 0 :(得分:3)

使用pickerView:viewForRow,并返回具有所需颜色的UILabel

- (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;
}

答案 1 :(得分:0)

试试这个: -

 - (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;
    }