设置 backgroundImage 后 UISegmentedControl tintcolor 无法工作

UISegmentedControl tintcolor can not work after setting backgroundImage

当我们不改变UISegmentedControl的背景图片时,设置tintcolor可以工作perfectly.But一旦我们改变背景图片,无论我们为tintcolor设置什么颜色,UIsegmentControl选择的颜色都会显示出来灰色 color.How 我可以在不自定义新 class 的情况下解决这个问题吗?

使用这个:

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UISegmentedControl *segmentedControl;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [self.segmentedControl setBackgroundImage:[UIImage imageNamed:@"blue.png"]
                                     forState:UIControlStateNormal
                                   barMetrics:UIBarMetricsDefault];

    [self.segmentedControl setBackgroundImage:[UIImage imageNamed:@"green.png"]
                                     forState:UIControlStateSelected
                                   barMetrics:UIBarMetricsDefault];
    self.segmentedControl.tintColor = [UIColor orangeColor];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

输出:

GitHub link:

https://github.com/k-sathireddy/SegmentedControlBackgroundWithTint