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
but obtain this:
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
Post a Comment