UISegmentedControl选择段颜色 [英] UISegmentedControl selected segment color

查看:164
本文介绍了UISegmentedControl选择段颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有任何方法自定义 UISegmentedControl

Is there any way to customize color of selected segment in UISegmentedControl?

c $ c> segmentedController.tintColor 属性,它允许我自定义整个分段控件的颜色。
问题是,当我为 tintColor 属性选择鲜艳的颜色时,所选段变得几乎无法识别(其颜色几乎与其他分段控件相同,因此)难以区分所选择和未选择的段)。所以我不能使用任何良好的明亮的颜色分段控制。
解决方案将是一些单独的属性为选定的段颜色,但我找不到它。有没有人解决这个问题?

I've found segmentedController.tintColor property, which lets me customize color of the whole segmented control. The problem is, when I select bright color for tintColor property, selected segment becomes almost unrecognizable (its color is almost the same as the rest of segmented control, so its hard to distinguish selected and unselected segments). So I cannot use any good bright colors for segmented control. The solution would be some separate property for selected segment color but I cannot find it. Did anyone solve this?

推荐答案

我发现一个简单的方法为UISegmentcontrol中的选定段添加颜色

I found A Simple Way to Add Color for Selected Segment in UISegmentcontrol

发件人是UISegmentControl

sender is 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];
    }
   else 
    {
        [[sender.subviews objectAtIndex:i] setTintColor:nil];
    }
}

检查其为我工作

这篇关于UISegmentedControl选择段颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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