iphone - UIImage position -


possible duplicate:
uiimage position

i'm using following code place images in uiview:

uiimage *image; uigraphicsbeginimagecontext(cgsizemake(480, 320)); int k=0; int posy=0;  (int i=0; i<[thearray count]; i++) {      image=[uiimage imagenamed:[nsstring stringwithformat:@"%@",[thearray objectatindex:i]]];     if (k>2) {         k=0;         posy++;     }             [image drawatpoint:cgpointmake(k*64, posy*23)];      k++;  }   uiimage *combinatedimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); 

obtaining result

http://cl.ly/8bsp

but obtain this:

http://cl.ly/8c6q

i can't figure out, confused. can me, please??? thanks!!

[solved]

this final working solution

uigraphicsbeginimagecontext(cgsizemake(480, 320));      int k=0;      int posy=0;      int d = 0;      (int i=0; i<[thearray count]; i++) {         int imagesleft = min(3, [thearray count]-i);         image=[uiimage imagenamed:[nsstring stringwithformat:@"%@",[thearray objectatindex:i]]];          if (k>2) {             k=0;               d=(3-imagesleft)*32;              posy++;          }          [image drawatpoint:cgpointmake(k*64+d, posy*23)];           k++;          nslog(@"image nr. %i = %i",i,imagesleft);     }     uiimage *combinatedimage = uigraphicsgetimagefromcurrentimagecontext();      uigraphicsendimagecontext(); 

thanks suggestions!

you're drawing image @ position defined by

[image drawatpoint:cgpointmake(k*64, posy*23)]; 

when go second row reset k zero. it's going draw left-aligned, first row. need add "delta":

int k=0; int posy=0; int delta = 0;  (int i=0; i<[thearray count]; i++) {  image=[uiimage imagenamed:[nsstring stringwithformat:@"%@",[thearray objectatindex:i]]]; if (k>2) {     k=0;     posy++;     delta = 30; }         [image drawatpoint:cgpointmake(k*64 + delta, posy*23)];  k++; } 

of course, works 5 elements. if don't know how many elements you'll have in row, need precompute add appropriate delta last row.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -