[英]Swift Change height of UISlider
I'm trying to change the height of a UISlider. 我正在尝试改变UISlider的高度。 This is what I am currently doing:
这就是我目前正在做的事情:
class CustomSlider: UISlider {
override func trackRect(forBounds bounds: CGRect) -> CGRect {
var newBounds = super.trackRect(forBounds: bounds)
newBounds.size.height = 20.0
return newBounds
}
@IBInspectable var thumbImage: UIImage? {
didSet {
setThumbImage(thumbImage, for: .normal)
}
}
@IBInspectable var thumbHighlightedImage: UIImage? {
didSet {
setThumbImage(thumbImage, for: .highlighted)
}
}
}
It seems to work for the most part, but I run into an issue that when the slider gets to the end, it is no longer rounded as you can see in the following image: 它似乎在大多数情况下都有效,但是我遇到了一个问题,当滑块到达终点时,它不再是圆角,如下图所示:
Is there any way to resolve this? 有什么方法可以解决这个问题吗? I'd prefer to stick with the system slider and not a custom one.
我更喜欢坚持系统滑块,而不是自定义滑块。
Edit: Changed image. 编辑:更改图像。
Swift 4.2 Swift 4.2
import UIKit
@IBDesignable open class DesignableSlider: UISlider {
@IBInspectable var trackHeight: CGFloat = 5
@IBInspectable var roundImage: UIImage? {
didSet{
setThumbImage(roundImage, for: .normal)
}
}
@IBInspectable var roundHighlightedImage: UIImage? {
didSet{
setThumbImage(roundHighlightedImage, for: .highlighted)
}
}
override open func trackRect(forBounds bounds: CGRect) -> CGRect {
//set your bounds here
return CGRect(origin: bounds.origin, size: CGSize(width: bounds.width, height: trackHeight))
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.