It may not be fully suited to answer this question, in iOS 7 and later you can adjust the color this way:
In delegate methods
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
add next
[[pickerView.subviews objectAtIndex:1] setBackgroundColor:NEEDED_COLOR]; [[pickerView.subviews objectAtIndex:2] setBackgroundColor:NEEDED_COLOR];
UPDATE
The previous code works, but so-so. Here are simple subclasses for UIPickerView
Swift:
class RDPickerView: UIPickerView { @IBInspectable var selectorColor: UIColor? = nil override func didAddSubview(subview: UIView) { super.didAddSubview(subview) if let color = selectorColor { if subview.bounds.height <= 1.0 { subview.backgroundColor = color } } } }
Objective-C:
@interface RDPickerView : UIPickerView @property (strong, nonatomic) IBInspectable UIColor *selectorColor; @end @implementation RDPickerView - (void)didAddSubview:(UIView *)subview { [subview didAddSubview:subview]; if (self.selectorColor) { if (subview.bounds.size.height <= 1.0) { subview.backgroundColor = self.selectorColor; } } } @end
and you can set the color of the selector directly in the storyboard
Thanks to Ross Barbish - "With the release of iOS 9.2 and XCode 7.2 on 12/8/2015, the height of this choice is 0.666666666666666."
UPDATE:
This fix is ββfor an issue with iOS 10, but not good, but it works.: /
class RDPickerView: UIPickerView { @IBInspectable var selectorColor: UIColor? = nil override func didAddSubview(_ subview: UIView) { super.didAddSubview(subview) guard let color = selectorColor else { return } if subview.bounds.height <= 1.0 { subview.backgroundColor = color } } override func didMoveToWindow() { super.didMoveToWindow() guard let color = selectorColor else { return } for subview in subviews { if subview.bounds.height <= 1.0 { subview.backgroundColor = color } } } }
Thanks, Dmitry Klochkov, I will try to find the best solution.
source share