0
這是我要的效果:在UISegmentedControl中,如何將正常顏色與所選顏色分開設置?
這是我到目前爲止有:
可可不允許同時設置圖標和每段的文字,所以我被迫將文字刻錄成圖像:
self.segmentedControl = [[UISegmentedControl alloc] initWithItems:@[
[UIImage imageNamed:@"segmentedControlContacts"],
[UIImage imageNamed:@"segmentedControlOtherApps"]
]];
我必須完成的最後一件事是將正常(未選中)的片段變成灰色,而不是其選定的/淡色的藍色。以下沒有工作:
// themeColor is defined as a shade of blue in a category
[UIView appearance].tintColor = [UIColor themeColor];
[[UISegmentedControl appearance]
setBackgroundImage:[UIImage imageNamed:@"segmentedControlEdgeNormal"]
forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance]
setBackgroundImage:[UIImage imageNamed:@"segmentedControlEdgeSelected"]
forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance]
setTitleTextAttributes:@{
NSForegroundColorAttributeName: [UIColor grayColor]
}
forState:UIControlStateNormal
];