0

I'm trying to do a custom uislider using images (without a visible knob, i hide it when user can't edit and show it when he can) The problem is that the the side render perfectly but the right part is cute and doesn't seems to use the edges... Any idea how i can edit it ?

Actual code :

    let capLeft:CGFloat =  9
    let capRight:CGFloat = 9
    imageMin = imageMinimum?.resizableImage(withCapInsets: UIEdgeInsets(top: 0, left: capLeft, bottom: 0, right: capRight), resizingMode: .stretch)
    imageMax = imageMaximum
    slider.setMaximumTrackImage(imageMax, for: UIControlState())
    slider.setMinimumTrackImage(imageMin, for: UIControlState())

How it's rendering : bad slider rendering

How it should render : good Rendering

Minimum track image : enter image description here

Maximum Tracking Image : enter image description here

Do you have any idea ?

Kevin Vacquier
  • 622
  • 6
  • 17

1 Answers1

0

I think there is a bit of confusion about Min and Max images with UISlider.

The Min image is drawn (and stretched) on the Left side of the Thumb. The Max image is drawn (and stretched) on the Right side of the Thumb.

Create a small, square solid red image - such as 16x16 - and assign it (without insets) to .setMaximumTrackImage. See how that ends up looking, as you go from low to high values.

Edit: I used NO insets on the Min image for this example...

enter image description here enter image description here

Note: I used a 20x20 clear image for the Thumb in these caps.

DonMag
  • 69,424
  • 5
  • 50
  • 86
  • That's one of the bleh i was winging about, i will seperate the grey from the black but that does not explain why the edges are "cut" – Kevin Vacquier Apr 03 '17 at 07:11