|  | @@ -7,93 +7,86 @@
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  import Foundation
 |  |  import Foundation
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -class BFUISlider: UISlider {
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    //slider的value文本
 |  | 
 | 
											
												
													
														|  | -    var valueText:String?{
 |  | 
 | 
											
												
													
														|  | 
 |  | +public class BFUISlider: UISlider {
 | 
											
												
													
														|  | 
 |  | +    // slider的value文本
 | 
											
												
													
														|  | 
 |  | +    public var valueText: String? {
 | 
											
												
													
														|  |          didSet {
 |  |          didSet {
 | 
											
												
													
														|  |              valueLabel.text = valueText
 |  |              valueLabel.text = valueText
 | 
											
												
													
														|  |              valueLabel.sizeToFit()
 |  |              valueLabel.sizeToFit()
 | 
											
												
													
														|  | -            
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |              let trackRect = convert(bounds, to: nil)
 |  |              let trackRect = convert(bounds, to: nil)
 | 
											
												
													
														|  |              let thumbRectTemp = thumbRect(forBounds: bounds, trackRect: trackRect, value: value)
 |  |              let thumbRectTemp = thumbRect(forBounds: bounds, trackRect: trackRect, value: value)
 | 
											
												
													
														|  | -            valueLabel.center = CGPoint.init(x: (thumbRectTemp.origin.x - thumbRectTemp.origin.x + thumbRectTemp.size.width / 2), y: -self.frame.size.height)
 |  | 
 | 
											
												
													
														|  | -            
 |  | 
 | 
											
												
													
														|  | 
 |  | +            valueLabel.center = CGPoint(x: thumbRectTemp.origin.x - thumbRectTemp.origin.x + thumbRectTemp.size.width / 2, y: -self.frame.size.height)
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  //            CGPointMake((thumbRect.origin.x - trackRect.origin.x + thumbRect.size.width / 2), -self.frame.size.height);
 |  |  //            CGPointMake((thumbRect.origin.x - trackRect.origin.x + thumbRect.size.width / 2), -self.frame.size.height);
 | 
											
												
													
														|  | -            
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  //            [super trackRectForBounds:bounds];
 |  |  //            [super trackRectForBounds:bounds];
 | 
											
												
													
														|  |  //           return CGRectMake(bounds.origin.x, bounds.origin.y + (bounds.size.height - 3.0) / 2, bounds.size.width, 3.0);
 |  |  //           return CGRectMake(bounds.origin.x, bounds.origin.y + (bounds.size.height - 3.0) / 2, bounds.size.width, 3.0);
 | 
											
												
													
														|  | -       
 |  | 
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | -    override var value: Float{
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    override public var value: Float {
 | 
											
												
													
														|  |          didSet {
 |  |          didSet {
 | 
											
												
													
														|  |              sliderValueChanged(sender: self)
 |  |              sliderValueChanged(sender: self)
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | -    //slider的value字体
 |  | 
 | 
											
												
													
														|  | -    var valueFont:UIFont?
 |  | 
 | 
											
												
													
														|  | -    //slider的value文本颜色
 |  | 
 | 
											
												
													
														|  | -    var valueTextColor:UIColor?
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    //返回的数值是否为整形
 |  | 
 | 
											
												
													
														|  | -    var valueIsInt:Bool = false
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    lazy var valueLabel:UILabel = {
 |  | 
 | 
											
												
													
														|  | -        let valueLabel = UILabel.init()
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    // slider的value字体
 | 
											
												
													
														|  | 
 |  | +    public var valueFont: UIFont?
 | 
											
												
													
														|  | 
 |  | +    // slider的value文本颜色
 | 
											
												
													
														|  | 
 |  | +    public var valueTextColor: UIColor?
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    // 返回的数值是否为整形
 | 
											
												
													
														|  | 
 |  | +    public var valueIsInt: Bool = false
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    public lazy var valueLabel: UILabel = {
 | 
											
												
													
														|  | 
 |  | +        let valueLabel = UILabel()
 | 
											
												
													
														|  |          valueLabel.text = "0"
 |  |          valueLabel.text = "0"
 | 
											
												
													
														|  |          valueLabel.textColor = valueTextColor != nil ? valueTextColor : self.thumbTintColor
 |  |          valueLabel.textColor = valueTextColor != nil ? valueTextColor : self.thumbTintColor
 | 
											
												
													
														|  | -        valueLabel.font = valueFont != nil ? valueFont : UIFont.systemFont(ofSize: 14);
 |  | 
 | 
											
												
													
														|  | 
 |  | +        valueLabel.font = valueFont != nil ? valueFont : UIFont.systemFont(ofSize: 14)
 | 
											
												
													
														|  |          valueLabel.textAlignment = .center
 |  |          valueLabel.textAlignment = .center
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |          return valueLabel
 |  |          return valueLabel
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |      }()
 |  |      }()
 | 
											
												
													
														|  | -    override init(frame: CGRect) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    override public init(frame: CGRect) {
 | 
											
												
													
														|  |          super.init(frame: frame)
 |  |          super.init(frame: frame)
 | 
											
												
													
														|  |          addTarget(self, action: #selector(sliderTouchDown(sender:)), for: .touchDown)
 |  |          addTarget(self, action: #selector(sliderTouchDown(sender:)), for: .touchDown)
 | 
											
												
													
														|  |          addTarget(self, action: #selector(sliderValueChanged(sender:)), for: .valueChanged)
 |  |          addTarget(self, action: #selector(sliderValueChanged(sender:)), for: .valueChanged)
 | 
											
												
													
														|  |          addTarget(self, action: #selector(sliderTouchUpInside(sender:)), for: .touchUpInside)
 |  |          addTarget(self, action: #selector(sliderTouchUpInside(sender:)), for: .touchUpInside)
 | 
											
												
													
														|  | - 
 |  | 
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    required init?(coder: NSCoder) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    public required init?(coder _: NSCoder) {
 | 
											
												
													
														|  |          fatalError("init(coder:) has not been implemented")
 |  |          fatalError("init(coder:) has not been implemented")
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    override func layoutSubviews() {
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    override public func layoutSubviews() {
 | 
											
												
													
														|  |          super.layoutSubviews()
 |  |          super.layoutSubviews()
 | 
											
												
													
														|  |          addSubview(valueLabel)
 |  |          addSubview(valueLabel)
 | 
											
												
													
														|  |          sliderValueChanged(sender: self)
 |  |          sliderValueChanged(sender: self)
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    override func setValue(_ value: Float, animated: Bool) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    override public func setValue(_ value: Float, animated: Bool) {
 | 
											
												
													
														|  |          super.setValue(value, animated: animated)
 |  |          super.setValue(value, animated: animated)
 | 
											
												
													
														|  |          sliderValueChanged(sender: self)
 |  |          sliderValueChanged(sender: self)
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | - 
 |  | 
 | 
											
												
													
														|  | -    //重写方法-返回进度条的bounds-修改进度条的高度
 |  | 
 | 
											
												
													
														|  | -    override func trackRect(forBounds bounds: CGRect) -> CGRect {
 |  | 
 | 
											
												
													
														|  | - 
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    // 重写方法-返回进度条的bounds-修改进度条的高度
 | 
											
												
													
														|  | 
 |  | +    override public func trackRect(forBounds bounds: CGRect) -> CGRect {
 | 
											
												
													
														|  |          let bounds = super.trackRect(forBounds: bounds)
 |  |          let bounds = super.trackRect(forBounds: bounds)
 | 
											
												
													
														|  | -        return CGRect.init(origin: CGPoint.init(x: bounds.origin.x, y: bounds.origin.y + (bounds.size.height - 3.0) / 2 ), size: CGSize.init(width:  bounds.size.width, height: 3))
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    @objc func sliderTouchDown(sender: BFUISlider) {
 |  | 
 | 
											
												
													
														|  | -         
 |  | 
 | 
											
												
													
														|  | 
 |  | +        return CGRect(origin: CGPoint(x: bounds.origin.x, y: bounds.origin.y + (bounds.size.height - 3.0) / 2), size: CGSize(width: bounds.size.width, height: 3))
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | -    @objc func sliderValueChanged(sender: BFUISlider) {
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        if(valueIsInt){
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    @objc public func sliderTouchDown(sender _: BFUISlider) {}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    @objc public func sliderValueChanged(sender: BFUISlider) {
 | 
											
												
													
														|  | 
 |  | +        if valueIsInt {
 | 
											
												
													
														|  |              valueText = "\(Int(sender.value))x"
 |  |              valueText = "\(Int(sender.value))x"
 | 
											
												
													
														|  | -        }else{
 |  | 
 | 
											
												
													
														|  | 
 |  | +        } else {
 | 
											
												
													
														|  |              valueText = "\(sender.value.decimalString())x"
 |  |              valueText = "\(sender.value.decimalString())x"
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -      
 |  | 
 | 
											
												
													
														|  | - 
 |  | 
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | -    @objc func sliderTouchUpInside(sender: BFUISlider) {
 |  | 
 | 
											
												
													
														|  | -         
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    @objc public func sliderTouchUpInside(sender _: BFUISlider) {}
 | 
											
												
													
														|  |  }
 |  |  }
 |