【问题标题】:How do you make the selected segment of a UISegmentedControl darker?如何使 UISegmentedControl 的选定段变暗?
【发布时间】:2012-04-04 04:21:58
【问题描述】:

我正在使用 UIAppearance 为我的 iOS 应用设置全局样式。我正在设想一种浅灰色的风格。

[[UINavigationBar appearance]
    setTintColor:[UIColor colorWithWhite:0.95 alpha 1.0]
];

[[UISegmentedControl appearance]
    setTintColor:[UIColor colorWithWhite:0.90 alpha 1.0]
];

问题是UISegmentedControl 的选定段(Uno)并不比正常段(Dos)暗多少。正常段已经在正确的黑暗中,但我只想使选定的段变暗,这样人们就可以分辨出两者之间的区别。变暗色调会同时使它们两个变暗,所以这是行不通的。

【问题讨论】:

    标签: iphone ios cocoa-touch


    【解决方案1】:

    最简单的方法是遍历分段控制器的子视图列表并查看选择了哪个,当您找到选定的子视图时,您需要将其色调调整为更暗。

    for (int x= 0; x <[aSegementedController.subviews count]; x++) 
    {
        UIBarButtonItem *subview = [aSegementedController.subviews objectAtIndex:x];
        if ([subview isSelected]) 
        {               
    
            [subview setTintColor:darkerColor];
        }
    }
    

    然而,这不适用于 UIAppearance,我不相信它在那个级别是可定制的。

    【讨论】:

    • 我继承了 UISegmentedControl。在这个子类中,我如何监听更改事件并执行您的示例代码?我认为 UISegmentedControl 处理自己的样式会更干净,而不是 UIViewController 监听更改然后告诉 UISegmentedControl 更改其色调。
    • 没关系。我刚刚意识到,视图理解事件是违反模型-视图-控制器范式的。
    猜你喜欢
    • 2011-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-15
    • 2017-05-23
    • 2021-12-10
    • 1970-01-01
    相关资源
    最近更新 更多