How to change UIPicker Color ? iPhone

前端 未结 6 866
走了就别回头了
走了就别回头了 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:17

    This is the best solution I have found

    http://www.inexika.com/blog/Customizing-UIPickerView-UIDatePicker

    0 讨论(0)
  • 2020-12-30 18:19

    Create a single overlay image as Amagrammer suggested but instead of adding it to your view as an image, add it as a button. Then disable the interaction on the button and the picker will receive the touch events without the need to intercept or override anything.

    0 讨论(0)
  • 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;
    }
    
    0 讨论(0)
  • 2020-12-30 18:29

    You can create your own custom pickers, check the UICatalog sample project at apples site, they show how to make a custom picker, it might help you https://developer.apple.com/iphone/library/samplecode/UICatalog/

    0 讨论(0)
  • 2020-12-30 18:35

    I assume all you want to change is the color of the border of the picker, not of the region in the center with which the user interacts. In this case, do the following:

    Create 4 "cover" UIViews and add them directly to the UIPicker, as in:

    [picker addSubview: coverView];
    

    Position these views over the top, bottom, left and right sides of the picker border. (You will need to experiment with sizes.) Set the backgroundColor of the coverViews to the color you want, and adjust the alpha to get the gradient shading from the picker. Again, this may take a bit of experimentation.

    The alternative would be to create one big coverView that covers the entire picker, and override the - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event method so that your cover view did not intercept the touches meant for the picker.

    0 讨论(0)
  • 2020-12-30 18:39

    You can do this by adding 5 ImageView also. First one is of size "Selection Indicator" and put it exactly over "Selection Indicator". Now change that imageView's alpha to 0.2 or whatever you want and also add image/color as per your choice. Now, you will see your custom "Selection Indicator". Also, same thing you can do for borders. Add each imageView to four sides of pickerview and make it's size equal to border size. Now fill the images/color you want in that ImageView.

    0 讨论(0)
提交回复
热议问题