How to change UIPicker Color ? iPhone

前端 未结 6 914
走了就别回头了
走了就别回头了 2020-12-30 17:35

I have observed that UIPicker always remains in black color,

Is there any way to change the color of UIPicker & it\'s Selection Indicator?

Thanks for hel

6条回答
  •  忘掉有多难
    2020-12-30 18:28

    You'll need to create a new UIView with a UIImageView inside it and then set that as the Accessory for the cell. So you'll need to create a image just like the default accessory but in the color you want.

    UIView* accessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 24, 50)];
    UIImageView* accessoryViewImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"NEWIMAGE.png"]];
    accessoryViewImage.center = CGPointMake(12, 25);
    [accessoryView addSubview:accessoryViewImage];
    [cell setAccessoryView:accessoryView];
    [accessoryViewImage release];
    [accessoryView release];
    

    for changing text color here's the solution

    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
    
    CGRect imageFrame = CGRectMake(0.0, 0.0, 15, 15);
    UIImageView *label = [[[UIImageView alloc] initWithFrame:imageFrame] **autorelease**];
    
    if (row == 0)
    {
        label.backgroundColor = [UIColor redColor];
    }
    if (row == 1)
    {
        label.backgroundColor = [UIColor blueColor];
    }
    if (row == 2)
    {
        label.backgroundColor = [UIColor blackColor];
    }   
    return label;
    }
    

提交回复
热议问题