Re: UISlider with custom images & narrow thumb
Re: UISlider with custom images & narrow thumb
- Subject: Re: UISlider with custom images & narrow thumb
- From: Fritz Anderson <email@hidden>
- Date: Sat, 28 Dec 2013 19:14:29 -0600
On 21 Nov 2013, at 8:36 AM, John Spicer <email@hidden> wrote:
> I'm trying to get a UISlider working with custom images. I've gone through the docs, and I know how to set the images.
> The question (and the problem) is a little different.
>
> Our design department has given us a thumb image that is wide at the bottom, and narrow at the top (1 pixel).
>
> When I use this image, it does not line up properly with the current value of the slider.
UISlider takes a UIImage as its thumb image. UIImage and UISlider do not care about the bit-by-bit drawable content of the image. All they know is that if you initialize a UIImage from a 24 x 24-point PNG, the image is 24 x 24 points in size. Is the drawn content 24 x 24 of black pixels? A circle, which is necessarily 24 points wide at the middle? 24 x 24 of transparent pixels? A black triangle that's half the pixel width at the middle?
Does not matter. The thumb image will be drawn so at the extremes of the slider, the image (not its drawn content) is flush against the end of the track. Run the experiment with two sliders, one with your image and the other with the default one, and you'll see they behave identically. They line up properly; they just don't line up as you'd hoped.
> All the examples I've seen on the net show a thumb that's fairly fat and round – never one like I've been given.
> The docs don't SAY you have to use a fat one, but it seems implied.
And anyone who attempts anything else soon finds out. If you care, find the part of the documentation where you think the warning ought to go (maybe the Sliders section of UIKit User Interface Catalog), and click the feedback link.
>
> So the question is: can I use a thumb like this, and if so, how do I get the positioning of the narrow top of the image (center) to align with the current value of the slider?
Your premise is incorrect. The thumb _is_ aligned with the current value of the slider. What surprises you is that you didn't know that UISlider does not draw the thumb outside the frame of the control, and that you assumed UISlider knew, in this particular case, what part of the thumb you find most significant.
If the track is the problem, use a house shape, or a diamond, or something else that takes the full width of the image at the middle. Or maybe you can do something with the track images like providing images that are transparent for as much of the track as you want to hide.
If you're trying to line up with tick marks in an adjacent view, place the marks to line up with the actual positioning of the thumb.
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden