ios - 如何通过 Storyboard设置 UISegmentedControl 背景图像?

标签 ios uiimage uisegmentedcontrol

在 iOS 应用程序中,我当前的男性和女性 UISegmented 控件如下所示:

enter image description here

现在我想更改这些片段的背景图片。所以我在 Storyboard中更改如下:

 For Segment 0:

enter image description here

 For Segment 1:

enter image description here

 After this changes,I got the result as below :

enter image description here

为什么这些图像相互重叠?任何特定原因或这些段的大小是否根据图像大小?如何在不影响段大小的情况下设置段的背景图像(完整图像应显示在段的背景中而不是重叠)?

我们将不胜感激。

最佳答案

尝试在这样的代码中进行自定义。

[self.segmentedControl setDividerImage:[UIImage imageNamed:@"style_segmented_control_delimiter.png"]
                     forLeftSegmentState:UIControlStateSelected
                       rightSegmentState:UIControlStateNormal
                              barMetrics:UIBarMetricsDefault];

  [self.segmentedControl setDividerImage:[UIImage imageNamed:@"style_segmented_control_delimiter.png"]
                     forLeftSegmentState:UIControlStateNormal
                       rightSegmentState:UIControlStateNormal
                              barMetrics:UIBarMetricsDefault];

  [self.segmentedControl setBackgroundImage:[UIImage imageNamed:@"style_segmented_control_normal_mid.png"]
                                   forState:UIControlStateNormal
                                 barMetrics:UIBarMetricsDefault];

  [self.segmentedControl setBackgroundImage:[UIImage imageNamed:@"style_segmented_control_press_mid.png"]
                                   forState:UIControlStateSelected
                                 barMetrics:UIBarMetricsDefault];

关于ios - 如何通过 Storyboard设置 UISegmentedControl 背景图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18430419/

相关文章:

ios - iOS13 新的 SegmentedControl 外观是否可供公众使用

ios - 切换到 UITabBarController 内的分段控件索引

ios - NSSortDescriptor与Comparator使用实际对象而不是键值

iphone - 如何在 iPhone 中为透明的 PNG 图像着色?

ios - 想要按钮吞下所有的触摸

swift - 表达式类型 UIImage 在没有更多上下文的情况下不明确

ios - UIImage 从文件加载时占用大量内存

ios - 来自扩展的分段控制 subview

ios - 如何向 UITableViewCell 添加触摸识别器?

ios - 单元格的 UITableView 处理程序将隐藏