Featured post
objective c - UISlider with ProgressView combined -
is there apple-house-made way uislider progressview. used many streaming applications e.g. native quicktimeplayer or youtube. (just sure: i'm in visualization interested)
cheers simon
here's simple version of you're describing.
it "simple" in sense didn't bother trying add shading , other subtleties. it's easy construct , can tweak draw in more subtle way if like. example, make own image , use slider's thumb.
this uislider subclass lying on top of uiview subclass (mytherm) draws thermometer, plus 2 uilabels draw numbers.
the uislider subclass eliminates built-in track, thermometer behind shows through. uislider's thumb (knob) still draggable in normal way, , can set custom image, value changed event when user drags it, , on. here code uislider subclass eliminates own track:
- (cgrect)trackrectforbounds:(cgrect)bounds { cgrect result = [super trackrectforbounds:bounds]; result.size.height = 0; return result; }
the thermometer instance of custom uiview subclass, mytherm. instantiated in nib , unchecked opaque , gave background color of clear color. has value
property knows how fill thermometer. here's drawrect:
code:
- (void)drawrect:(cgrect)rect { cgcontextref c = uigraphicsgetcurrentcontext(); [[uicolor whitecolor] set]; cgfloat ins = 2.0; cgrect r = cgrectinset(self.bounds, ins, ins); cgfloat radius = r.size.height / 2.0; cgmutablepathref path = cgpathcreatemutable(); cgpathmovetopoint(path, null, cgrectgetmaxx(r) - radius, ins); cgpathaddarc(path, null, radius+ins, radius+ins, radius, -m_pi/2.0, m_pi/2.0, true); cgpathaddarc(path, null, cgrectgetmaxx(r) - radius, radius+ins, radius, m_pi/2.0, -m_pi/2.0, true); cgpathclosesubpath(path); cgcontextaddpath(c, path); cgcontextsetlinewidth(c, 2); cgcontextstrokepath(c); cgcontextaddpath(c, path); cgcontextclip(c); cgcontextfillrect(c, cgrectmake(r.origin.x, r.origin.y, r.size.width * self.value, r.size.height)); }
to change thermometer value, change mytherm instance's value
number between 0 , 1, , tell redraw setneedsdisplay
.
- Get link
- X
- Other Apps
Comments
Post a Comment