ios - How to add a another image to Thumb of a slider or How to add two thumb images? -
i building ios app using storyboards.i facing critical issue now. created slider programmatically. added thumb image own custom image. want increase , decrease width on button click. these working fine. thing want is, want add image under thumb image. image newly added should move respective thumb image.
this method create lot of complications.better create custom slider.everything have created programmatically.
declare views , frames shown below.
uiview *slider,*timeline,*mainview; uiview *thumb; cgrect sliderframe,thumbframe; -(void)createtimeline { timeline = [[uiview alloc]initwithframe:cgrectmake(0, 0, mainview.frame.size.width, 10)]; timeline.backgroundcolor=[uicolor colorwithred:224.0/255.0f green:224.0/255.0f blue:224.0/255.0f alpha:1.0]; [mainview addsubview:timeline]; [self createslider]; [self createthumb]; } -(void)createslider { sliderframe=cgrectmake(50, 0, delta, 10); slider=[[uiview alloc]initwithframe:sliderframe]; slider.backgroundcolor=[uicolor colorwithred:0.0/255.0f green:102.0/255.0f blue:0.0/255.0f alpha:1.0]; [mainview addsubview:slider]; [slider bringsubviewtofront:mainview]; } -(void)createthumb{ uiimage * thumbimage = [uiimage imagenamed:@"games@2x.png"]; float actualheight = thumbimage.size.height; float actualwidth = thumbimage.size.width; thumbframe = cgrectmake((fabs(actualwidth - sliderframe.size.width))/2,timeline.frame.size.height,actualwidth,actualheight); thumb=[[uiview alloc]initwithframe:thumbframe]; thumb.center = cgpointmake(sliderframe.origin.x + sliderframe.size.width/2, sliderframe.size.height+thumbframe.size.height/2); thumb.backgroundcolor= [uicolor colorwithpatternimage:thumbimage]; thumb.userinteractionenabled = yes; [mainview insertsubview:thumb atindex:mainview.subviews.count]; uipangesturerecognizer *move=[[uipangesturerecognizer alloc]initwithtarget:self action:@selector(drag:)]; move.maximumnumberoftouches = 1; move.minimumnumberoftouches = 1; [thumb addgesturerecognizer:move]; } -(void)drag:(uipangesturerecognizer *)pangesturerecognizer { cgpoint touchlocation = [pangesturerecognizer locationinview:mainview]; if (pangesturerecognizer.state == uigesturerecognizerstatebegan) { } else if (pangesturerecognizer.state == uigesturerecognizerstatechanged) { if ((touchlocation.x>(timeline.frame.origin.x-(thumbframe.size.width/2))) && (touchlocation.x <= (timeline.frame.size.width-(thumbframe.size.width/2)))) { thumbframe.origin.x =touchlocation.x; thumb.frame = thumbframe; sliderframe.origin.x = touchlocation.x + (thumbframe.size.width - sliderframe.size.width)/2; slider.frame = sliderframe; } } else if (pangesturerecognizer.state == uigesturerecognizerstateended) { } } pangesture applied moving thumbimage.
Comments
Post a Comment