ios - How to display images on button action -


i have 10 uiimages. when click uibutton displaying under uiscrollview. need implement theuibuttonlike **next**, ifuibuttonis clicked first time, displays firstuiimage`, after that, on click displays next image. if click button, previous image should displayed.

enter image description here

int   currentindex = 0; int max_count;  nsmutablearray *imagename = [[nsmutablearray alloc] initwithobjects:                                 @"spices.jpg",                                 @"spice_powder.jpg",                                  @"turmeric.jpg",                                 @"whynani_img3.jpg",                                 @"spice_blends.jpg",                                 @"products1.png", nil];  currentindex = currentindex + 1; if(currentindex > max_count) {    currentindex = max_count; }          (int = 0; i<[imagename count]; i++ ) {     uiimageview  *mmageview =       [[uiimageview alloc] initwithframe:cgrectmake(200,200,350,350)];    [mmageview setimage:[uiimage imagenamed:[imagename objectatindex:i]]];                [self.view addsubview:mmageview];            } 

declare global imageview , int in interface file

uiimageview *imgview; int index; 

in viewdidload:

index = 0;  imgview = [[uiimageview alloc] initwithframe:cgrectmake(200,200,350,350)]; [imgview setimage:[uiimage imagenamed:[imagename objectatindex:index]]]; [self.view addsubview:imgview];  

in next button action

-(void)nextbuttonaction {   ++index;    [previousbtn setenabled:yes];     if (index > [imagename count])   {     index = [imagename count] - 1;     [nextbtn setenabled:no];   }    [imgview setimage:[uiimage imagenamed:[imagename objectatindex:index]]];  } 

in previous button action

-(void)previousbuttonaction {   --index;    [nextbtn setenabled:yes];     if (index < 0)   {     index = 0;     [previousbtn setenabled:no];   }    [imgview setimage:[uiimage imagenamed:[imagename objectatindex:index]]];  } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -