【问题标题】:UISlider track heightUISlider 轨道高度
【发布时间】:2017-01-31 13:45:15
【问题描述】:

我已经实现了 UISlider,我需要调整轨道高度。 我找到了这个,但它不起作用。

self.slider.trackRect(forBounds: CGRect(x: 0, y: 0, width: 100, height: 100))

【问题讨论】:

    标签: swift3 uislider


    【解决方案1】:

    好的...我使用了 matt 的答案 + 提供的示例,并根据我的需要自定义了代码。

    let coinEnd = UIImage(/*HERE_LEFT_BLANK_IMG*/).resizableImage(withCapInsets:
            UIEdgeInsetsMake(0,7,0,7), resizingMode: .stretch)
    .
    .
    .
    .
    
    override func trackRect(forBounds bounds: CGRect) -> CGRect {
        var result = super.trackRect(forBounds: bounds)
        result.origin.x = 0
        result.size.width = bounds.size.width
        result.size.height = 10 //added height for desired effect
        return result
    }
    
    override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect {
        return super.thumbRect(forBounds:
            bounds, trackRect: rect, value: value)
            .offsetBy(dx: 0/*Set_0_value_to_center_thumb*/, dy: 0)
    }
    

    然后将此继承给我的 Slider 和 woala。

    这是我想要的结果。

    万岁马特...谢谢。

    【讨论】:

      【解决方案2】:

      找到了,但是没有用

      因为你用错了。你不调用它。您继承并覆盖它。

      但是,正确的方法是为轨道提供新图像,setMinimumTrackImagesetMaximumTrackImage

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-08
      • 1970-01-01
      • 1970-01-01
      • 2011-05-08
      • 1970-01-01
      • 1970-01-01
      • 2014-06-12
      • 1970-01-01
      相关资源
      最近更新 更多