【问题标题】:UISegmentedContol change background color without changing image tint colorUISegmentedControl 更改背景颜色而不更改图像色调颜色
【发布时间】:2015-02-08 16:21:12
【问题描述】:

我有一个 UISegmentedContol,每个段内都有图像。在情节提要中,我将图像的背景颜色和色调设置为白色。 Now when one segment is selected, I am trying to change the background color only and keep the image tint to white (the same as the unselected segments) but I am unable to do so.这是我的代码:

- (IBAction)onSegmentValueChanged:(id)sender
{
    UISegmentedControl *segment = (UISegmentedControl*)sender;
    UIColor *tintcolor=UIColorFromRGB(0x3A0F3A);

    for (int i=0; i<[segment.subviews count]; i++)
    {
        if ([[segment.subviews objectAtIndex:i]isSelected] )
        {
            [[segment.subviews objectAtIndex:i] setBackgroundColor:[UIColor purpleColor]];
        [[segment.subviews objectAtIndex:i] setTintColor:[UIColor whiteColor]];
        }
        else
        {
            [[segment.subviews objectAtIndex:i] setBackgroundColor:tintcolor];
        }
    }    
}

见下图:

https://www.dropbox.com/s/y93m3vtgr95e2dy/IMG_9249.PNG?dl=0

未选择的片段具有正确的背景颜色(紫色)和正确的图像色调(白色)。所选片段应具有带有白色图像色调的紫色背景,但它具有白色背景。

谢谢

【问题讨论】:

    标签: ios objective-c uisegmentedcontrol


    【解决方案1】:

    我在之前的项目中也有类似的需求,为此我使用了PPiFlatSegmentedControl,它就像魔术一样工作。

    谢谢,

    态度

    【讨论】:

    • 效果很好。谢谢!
    【解决方案2】:

    对于所有带有段控制的附加功能,我使用的是自定义段控制。 例如你可以检查我的段控制。

    https://github.com/Bambaster/CustomSegmentControl

    因此您可以添加图像、颜色等。

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 2014-04-26
      • 1970-01-01
      • 1970-01-01
      • 2015-12-31
      • 2023-04-05
      • 1970-01-01
      • 2013-08-08
      相关资源
      最近更新 更多