ios - UISlider customization: how to properly add shadow to custom knob image -
i need place custom knob image shadow uislider. far have image of 38x38, of there region defines shadow of knob.
now while using image, when slide knob extreme ends actual knob not able cover end points, hence end points visible under transparent region of knob image
this code using customize uislider
uiimage *slidebtimg = [uiimage imagenamed:sliderknobimg];
[self.ratingslider setthumbimage:slidebtimg forstate:uicontrolstatenormal];
[self.ratingslider setthumbimage:slidebtimg forstate:uicontrolstatehighlighted];
how can implement custom knob shadow beneath it, covering end points??
look inside uislider.h
, there methods let customize slider knob , track needed. (ios 2.0 , above)
// lets subclass lay out track , thumb needed - (cgrect)minimumvalueimagerectforbounds:(cgrect)bounds; - (cgrect)maximumvalueimagerectforbounds:(cgrect)bounds; - (cgrect)trackrectforbounds:(cgrect)bounds; - (cgrect)thumbrectforbounds:(cgrect)bounds trackrect:(cgrect)rect value:(float)value;
here own example. requires math work. valueratio of current slider position (from 0 1) , adjust make shadowed custom knob nicely @ center. hope helps ;)
- (cgrect)thumbrectforbounds:(cgrect)bounds trackrect:(cgrect)rect value:(float)value { float valueratio = ( value - self.minimumvalue ) / valuerange; return cgrectmake(valueratio * (bounds.size.width - 26) + 3, 7, 20, 20); }