UISegmentedControl custom color

来源:互联网 发布:小志网络赚钱博客 编辑:程序博客网 时间:2024/06/04 17:43

simple code:   

 intindex =segControlStyle.selectedSegmentIndex   

      for(id viewin segControlStyle.subviews) {

          if ([viewisSelected]) {

              [viewsetTintColor:[UIColorredColor]];

           }else {

              [viewsetTintColor:[UIColorblackColor]];

           }

          

       }

       //code for hack(fitthe separator line bug)

    for(int i=[segControlStyle.subviewscount]; i>0; i--) {

          [segControlStylesetSelectedSegmentIndex:i-1];

         

       [segControlStylesetSelectedSegmentIndex:index]; 


注意两点:

1、segControlStyle.subviews中view的排列没有固定顺序,每一次都是随机的。所以不能够通过subviewsobjectAtIndex:selectedSegmentIndex来获取选中的view

2、如果不加hackcode的话,相邻选项卡之间会存在一条难看的分割线(在这里为红色),hackcode的灵感来源:

如果依次从右往左选择选项卡的话则不会有风格线产生

0 0
原创粉丝点击