【问题标题】:Adjusting UISlider thumb image调整 UISlider 拇指图像
【发布时间】:2021-10-15 16:54:36
【问题描述】:

所以我在我的自定义UISlider 中添加了一个拇指图像,如下所示:

self.setThumbImage(UIImage(named: "POITicker"), for: .normal)

但是你可以看到它没有居中。如何调整图像以使拇指居中于圆心?

【问题讨论】:

  • 您需要在圆的下方添加与圆上方的三角形所使用的一样多的“空白”。
  • @DonMag 我刚试过,没有运气
  • 在圆下添加一个三角形....看看你是否让圆以上下三角形为中心。

标签: ios swift uikit uislider


【解决方案1】:

这是您的自定义滑块,因此请覆盖 thumbRect(forBounds:...);这就是它的用途。

https://developer.apple.com/documentation/uikit/uislider/1621344-thumbrectforbounds

例如,你可能会说

override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect {
    return super.thumbRect(forBounds: bounds, trackRect: rect, value: value)
        .offsetBy(dx: 0, dy: -7)
}

除了你会通过眼球调整dy的值。

【讨论】:

    【解决方案2】:

    一个选项,它还为您提供了一个“更高”的拇指触摸区域:

    显然,使用透明背景而不是此处显示的绿色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多