Customizing UISlider look

前端 未结 7 566
萌比男神i
萌比男神i 2020-12-10 14:30

To customize the visual look of a UISlider you can set the thumb and track images. Part of the track images gets stretched to the appropriate with. From the documentation:

相关标签:
7条回答
  • 2020-12-10 15:06

    You could just create the images to be as wide as you need them to be, with the pattern pre-rendered.

    0 讨论(0)
  • 2020-12-10 15:11

    I wanted a pattern behind my UISlider. I ended up setting both images to nil and adding a view under the slider since I didn't need it to be different on either side of the thumb. This would be more difficult if you needed to change it based on the position, but quite doable.

    0 讨论(0)
  • 2020-12-10 15:12

    You need to initialize your image with stretchableImageWithLeftCapWidth:topCapHeight:. leftCapWidth and topCapHeight are read-only properties on image objects, but using that function you can set them. You only set the left and top because the left and right caps are the same size, and the top and bottom are also the same. So, to use a custom slider track with a left side size of 5 pixels, you need to have an image of 11 pixels wide, by whatever height you need: 5 for the left cap, 1 pixel wide that is stretched for the track, and 5 more for the right. Having not played with it, I don't know if using a topCapHeight greater than 0 works as expected, but I suspect it wouldn't cause a great deal of problems.

    0 讨论(0)
  • 2020-12-10 15:16

    Just use transparent images as track images, and put a UIImageView below :)

    0 讨论(0)
  • 2020-12-10 15:17

    to make your custom UISlider you have many ways. Depending on what customization you want. there are default properties you can set to customize your UIslider, like following: setThumbImage:forState: setMinimumTrackImage:forState: setMaximumTrackImage:forState: If you want further customization you can refer the below link https://medium.com/@0209neha/creating-a-custom-uislider-7756bf898832#.o1l4qhymo https://github.com/0209Neha/ExploringSlider

    0 讨论(0)
  • 2020-12-10 15:29

    I believe you'll have to write your own slider to do that. There seems to be no (public) API to change UISlider's behavior regarding the stretchable region.

    0 讨论(0)
提交回复
热议问题