【问题标题】:What is the color or tint of the bar style UISegmentedControl条形样式 UISegmentedControl 的颜色或色调是什么
【发布时间】:2013-07-26 13:17:45
【问题描述】:

我想制作一个按钮,其外观与条形样式段的其中一个段具有相同的外观,例如这种颜色:

但我不知道如何实现与它相同的渐变。我的目标是制作一个带有看起来相同但您可以选择多个“段”的按钮的段控件

【问题讨论】:

  • 为什么不把你上传到这里的图片,裁剪掉一部分渐变,然后用它作为可调整大小的图片?

标签: iphone ios objective-c


【解决方案1】:

1.要启用多选,请将分段控件的 Selection 属性配置为 Multiple 或搜索自定义多选段。

选择

指定分段控件的跟踪模式。可能的选项是:

Multiple:这对应于常量 NSSegmentSwitchTrackingSelectAny,指定可以选择任意段。

2.外观,使用背景渐变图片

[mySegmentedControl insertSegmentWithImage:[UIImage imageNamed:@"gradient.png"] atIndex:0 animated:YES];

更多信息请参考我的answer here

【讨论】:

  • 我看不到在哪里可以将控件设置为多个?
【解决方案2】:

如果您有用于渐变的选定图像和正常状态图像的图像,则可以使用这段代码。

UIImage *segmentNormal = [[UIImage imageNamed:@"segmentNormal.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[[UISegmentedControl appearance] setBackgroundImage:segmentNormal forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

UIImage *segmentSelected = [[UIImage imageNamed:@"segmentSelected.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[[UISegmentedControl appearance] setBackgroundImage:segmentSelected forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

【讨论】:

    【解决方案3】:

    你想要的都在这里link

    对于分段外观,您可以设置[UISegmentedControl appearance] 属性。

    【讨论】:

    • 我已经尝试过这个子类,但它不能在故事板中正常工作
    • @BluGeni:你是对的,你可以在故事板中以编程方式尝试这个
    猜你喜欢
    • 2012-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-16
    • 2023-03-29
    • 1970-01-01
    • 2018-03-01
    • 1970-01-01
    相关资源
    最近更新 更多