如何在UISegmentedControl中更改禁用段的色调颜色。 我得到了对segmentedControl.subviews进行排序的解决方案,下面是swift代码,请将其转换为目标c。
'import moment from 'moment';
答案 0 :(得分:2)
检查以下代码:
1.为所选分段指定绿色。(分段-2)
2.将蓝色分配给未选择但已启用的颜色(第1段和第3段)。
3.为禁用的段指定lightGray颜色。(段-4)
-(IBAction)segmentedTapped:(UISegmentedControl*)sender{
for(int i=0;i<[sender.subviews count];i++)
{
if ([[sender.subviews objectAtIndex:i]isEnabled])
{
if([[sender.subviews objectAtIndex:i]isSelected])
{
UIColor *tintcolor=[UIColor greenColor];
[[sender.subviews objectAtIndex:i] setTintColor:tintcolor]; //sets green color for selected segment which is enabled
}
else
{
[[sender.subviews objectAtIndex:i] setTintColor:[UIColor blueColor]]; //sets blue colour for remaining segments which are enabled but not selected.
}
}
else
{
[[sender.subviews objectAtIndex:i] setTintColor:[UIColor lightGrayColor]];//sets ight gray for disabled segment.
}
}
}
如果您想了解更多信息,请点击此处: