当我们不改变UISegmentedControl的背景图像时,设置tintcolor可以完美地工作。但是一旦我们改变背景图像,无论我们为tintcolor设置哪种颜色,UIsegmentControl选择的颜色都将以灰色显示。如何在不自定义新类的情况下解决此问题?
答案 0 :(得分:0)
使用此:
#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
https://github.com/k-sathireddy/SegmentedControlBackgroundWithTint