iOS 6中的分段控件tintColor [英] Segmented control tintColor in iOS 6

查看:114
本文介绍了iOS 6中的分段控件tintColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含8段的分段控件。我可以更改整个控件的默认色调,但是我可以为控件中的每个段设置不同的颜色吗?我找到了一个在5.1中使用调用此方法的新类的教程,

I have a segmented control with 8 segments. I can change the default tint-color of the whole control, BUT can I set a different color for each segment in the control? I found a tutorial that worked in 5.1 with a new class that calls this method,

-(void)setTintColor:(UIColor*)color forTag:(NSInteger)aTag{}

但它在iOS 6中不起作用。想法?

But it doesn't work in iOS 6. Any ideas?

推荐答案

此问题已在此处修复。由于格式问题,我无法粘贴源代码。
此处的示例代码。

This issue has been fixed here. I could not paste the source code due to formatting issues. Sample code here.

编辑:添加评论&来自链接和固定格式的代码。 ~olie

added comment & code from link and fixed formatting. ~olie

这是一个hacky修复。这会奏效。将您的代码放在ViewDidAppear中。这就行了。

Its a hacky fix. This will work. Place your code in ViewDidAppear. That will do the trick.

- (void)viewDidAppear:(BOOL)animated 
{
    [super viewDidAppear: animated];
    dispatch_async(dispatch_get_main_queue(), ^{
        for (int i = 0 ; i < [segmentControl.subviews count] ; i++)
        {
            if ([[segmentControl.subviews objectAtIndex: i] isSelected] )
            {
                [[segmentControl.subviews objectAtIndex: i] setTintColor: [UIColor blackColor]];
                break;
            }
        }
    }); 
}

这篇关于iOS 6中的分段控件tintColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆