2013-03-25 55 views
0

当您将tintColor设置为UISegmentedControl时,如果它的segmentedControlStyleUISegmentedControlStyleBar,则不再显示您选择哪个按钮。 valueChanged事件仍会触发,但所选按钮中没有任何颜色变化。没有办法显示选定的按钮,而不使用默认的蓝色风格离开控件?带tintColor的UISegmentedControl不显示选择?

回答

0

,如果你设置暗颜色TintColor,你不会得到效果,可用于该用途的光色像 把这个代码在UISegmentControl

for (int i=0; i<[[sender subviews] count]; i++) 
{ 
    if ([[[sender subviews] objectAtIndex:i]isSelected]) 
    { 
     UIColor *tintcolor=[UIColor redColor]; //your requiremnent color here 
     [[[sender subviews] objectAtIndex:i] setTintColor:tintcolor]; 
     break; 
    } 
} 

的变化的方法试试这个

+1

不设置blackColor,否则您将面临此问题。 – 2013-03-25 12:12:51

+0

其实我已selectsegmentindex值,我想设置色调为绿色选定的索引和灰色未选定的索引...但它不工作 – Shaunak 2013-03-25 12:15:14

0

添加颜色在UISegmentcontrol

这里发件人选择的片段是UISegmentControl

for (int i=0; i<[sender.subviews count]; i++) 
{ 
    if ([[sender.subviews objectAtIndex:i]isSelected]) 
    {    
    UIColor *tintcolor=[UIColor colorWithRed:127.0/255.0 green:161.0/255.0 blue:183.0/255.0 alpha:1.0]; 
    [[sender.subviews objectAtIndex:i] setTintColor:tintcolor]; 
    break; 
    } 
} 
+1

此代码工作只在segmentchanged事件,而不是从其他方法手动调用 – Shaunak 2013-03-25 12:18:44

+0

得到段控制通过UISegmentedControl * sender =(UISegmentedControl *)Sg; – iPatel 2013-03-25 12:21:51