gpt4 book ai didi

ios - 自定义分段控制

转载 作者:行者123 更新时间:2023-11-29 00:09:11 26 4
gpt4 key购买 nike

如何在 iOS UISegmentedControl (Objective-C) 中实现此目的

我想显示所选段控件的圆角选择。

enter image description here

任何帮助将不胜感激。

最佳答案

UISegmentedControl有一个部分 customization .

总结如下:您所要做的就是为不同的状态组合提供分隔符图像。这意味着您需要为以下状态总共提供 3 张图像:

  1. 两个未选中片段之间的图像
  2. 左侧选定片段与右侧未选定片段之间的图像
  3. 右侧选定片段与左侧未选定片段之间的图像

代码如下:

objective-C

// Image between two unselected segments.
[mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateNormal
rightSegmentState:UIControlStateNormal barMetrics:barMetrics];
// Image between segment selected on the left and unselected on the right.
[mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateSelected
rightSegmentState:UIControlStateNormal barMetrics:barMetrics];
// Image between segment selected on the right and unselected on the right.
[mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateNormal
rightSegmentState:UIControlStateSelected barMetrics:barMetrics];

swift

    // Image between two unselected segments.
mySegmentedControl.setDividerImage(myImage, forLeftSegmentState: UIControlState.Normal,
rightSegmentState: UIControlState.Normal, barMetrics: UIBarMetrics.Default)

// Image between segment selected on the left and unselected on the right.
mySegmentedControl.setDividerImage(myImage, forLeftSegmentState: UIControlState.Selected,
rightSegmentState: UIControlState.Normal, barMetrics: UIBarMetrics.Default)

// Image between segment selected on the right and unselected on the left.
mySegmentedControl.setDividerImage(myImage, forLeftSegmentState: UIControlState.Normal,
rightSegmentState: UIControlState.Selected, barMetrics: UIBarMetrics.Default)

这是一个post这解释了如何实现这一目标。

如果您看到链接的帖子,那是 3 张图片。附上截图供引用: enter image description here

关于ios - 自定义分段控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47073393/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com