I am trying to make a UISlider with a thick track. I tried This , and it almost works. However, when UISlider is first displayed, the track bar is normal. Only when he receives a touch event does he become fatter.
Here is the code I added to my subclass of UISlider, as recommended:
- (CGRect)trackRectForBounds:(CGRect)bounds { return bounds; }
I do not understand how this works, so I can not understand why it does not work perfectly. Here are my questions:
- How it works?
- How can I control how thick he makes the track?
- How can I make it affect the track when UISlider is drawn first?
Of course, the third question is the most important, although others will help me in my understanding.
Another thing to keep in mind: when it first appears, I will hide my thumb:
[slider setThumbImage:[[UIImage alloc] init] forState:UIControlStateNormal];
When the user touches the slider, I show my thumb as follows:
[slider setThumbImage:nil forState:UIControlStateNormal]
I mention this because I am wondering if this somehow interferes with the magic of trackRectForBounds.
Thanks!
source share