Objective c 如何更改UISegmentedControl中禁用段的着色颜色
如何在UISegmentedControl中更改禁用段的着色颜色。 我得到了对分段控件进行排序的解决方案。子视图,下面是swift代码,请将其转换为目标cObjective c 如何更改UISegmentedControl中禁用段的着色颜色,objective-c,swift,uisegmentedcontrol,Objective C,Swift,Uisegmentedcontrol,如何在UISegmentedControl中更改禁用段的着色颜色。 我得到了对分段控件进行排序的解决方案。子视图,下面是swift代码,请将其转换为目标c @IBAction func indexChanged(sender: UISegmentedControl) { let sortedViews = sender.subviews.sort( { $0.frame.origin.x < $1.frame.origin.x } ) for (index, view) in sort
@IBAction func indexChanged(sender: UISegmentedControl) {
let sortedViews = sender.subviews.sort( { $0.frame.origin.x < $1.frame.origin.x } )
for (index, view) in sortedViews.enumerate() {
if index == sender.selectedSegmentIndex {
view.tintColor = UIColor.blueColor()
} else {
view.tintColor = UIColor.lightGrayColor()
}
}
}
let sortedViews = segmentedControlOutletVariable.subviews.sort( { $0.frame.origin.x < $1.frame.origin.x } )
sortedViews[0].tintColor = UIColor.blueColor()
@iAction func indexChanged(发送方:UISegmentedControl){
让sortedView=sender.subviews.sort({$0.frame.origin.x<$1.frame.origin.x})
对于SortedView.enumerate()中的(索引、视图){
如果index==sender.selectedSegmentIndex{
view.tintColor=UIColor.blueColor()
}否则{
view.tintColor=UIColor.lightGrayColor()
}
}
}
让SortedView=segmentedControlOutletVariable.subviews.sort({$0.frame.origin.x<$1.frame.origin.x})
sortedViews[0]。tintColor=UIColor.blueColor()
检查以下代码:
1.将绿色指定给所选段。(段2)
2.将蓝色指定给未选择但已启用的(第1段和第3段)
3.为禁用的段指定浅灰色。(段-4)
-(iAction)分段显示:(UISegmentedControl*)发送方{
对于(int i=0;i实际上我想更改禁用段的着色颜色..请帮助如何对段控件子视图数组索引进行排序?@jasonfrank:我的代码将为禁用段指定浅灰色。您可以在那里设置所需的颜色。假设我们有3个段,其中一个段已选中,第二个段未选中,但启用,第三个段为disab乐,现在我想把第三个的颜色调成灰色
-(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.
}
}
}