我想知道是否有人知道如何将UIPickerView文本颜色更改为白色。我的代码如下:

码:

(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{

    [self.pickerView setValue:[UIColor whiteColor] forKey:@"textColor"];

}

任何想法?

最佳答案

使用此代码

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    UILabel *tView = (UILabel*)view;
    if (!tView)
    {
        tView = [[UILabel alloc] init];
        [tView setTextColor:[UIColor whiteColor]];
        [tView setFont:[UIFont fontWithName:@"font-name-here" size:15]];
        [tView setTextAlignment:NSTextAlignmentCenter];
    }
    // Fill the label text here
    return tView;
}

07-27 13:40