1
我实施了UISlider,需要调整轨道高度。 我发现这个,但它不工作。UISlider轨道高度
self.slider.trackRect(forBounds: CGRect(x: 0, y: 0, width: 100, height: 100))
我实施了UISlider,需要调整轨道高度。 我发现这个,但它不工作。UISlider轨道高度
self.slider.trackRect(forBounds: CGRect(x: 0, y: 0, width: 100, height: 100))
发现这一点,但因为你使用它错了它不工作
。你不要它叫它。你的子类,并且覆盖它。
但是,正确的做法是为该曲目提供新图像,其中setMinimumTrackImage
和setMaximumTrackImage
。
好的......我使用了马特的答案+提供的例子,我为我的需求定制了代码。
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。
这是我想要的结果。
所有冰雹无光......谢谢。
例如:https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch12p585slider/ch25p860slider/MySlider.swift – matt