ios - CGRect size and point coming back 0 -


i trying position these buttons in row in scrollview x , y position of cgrect buttons not populate , every variable width, height , x , y position seems print 0.

// create mutable array populate  imagenames = [[nsarray alloc] init]; nsmutablearray *mimagenames = [[nsmutablearray alloc] init];   // list of images  nsstring *img1 = @"moustache"; nsstring *img2 = @"whitem"; nsstring *img3 = @"blackm";   // add images mutable array  [mimagenames addobject:img1]; [mimagenames addobject:img2]; [mimagenames addobject:img3];   // set mutable array array;  imagenames = mimagenames; cgfloat contentsizewidth = 0.0; cgsize newsize = _scrollviewoutlet.frame.size;    for(int = 0; < [imagenames count]; i++){      nsdata *archiveddata = [nskeyedarchiver archiveddatawithrootobject:_firstimage];     uibutton *button = [nskeyedunarchiver unarchiveobjectwithdata: archiveddata];     [button addtarget:self action:@selector(badgepressed:) forcontrolevents:uicontroleventtouchupinside];      button.tag = i+1;      cgrect newframe = [button frame];     newframe.size.width = _firstimage.frame.size.width;     newframe.size.height = _firstimage.frame.size.height;     contentsizewidth = (20+button.frame.size.width) * i;     newframe.origin.x += (20+_firstimage.frame.size.width) * i;     newframe.origin.y =  _firstimage.frame.origin.y ;     [button setframe:newframe];       nslog(@"button frame size: %f", _firstimage.frame.size.width);      nsstring *imagename = [[imagenames objectatindex:i] stringbyappendingstring:@".png"];;       nsstring *documentsdirectory = [utils getdocumentsdirectorypath];      //uiimage *image = [utils loadimage:imagename oftype:@"png" indirectory:documentsdirectory];     uiimage *image = [uiimage imagenamed:imagename                       ];        [button setimage:image forstate:uicontrolstatenormal];     [button setimage:image forstate:uicontrolstateselected];     [[button imageview] setcontentmode: uiviewcontentmodescaleaspectfit];     [button setalpha:1.0f];     [[button imageview] setimage:image];       newsize.width += 10;     newsize.width = contentsizewidth+100;      [_scrollviewoutlet setcontentsize:newsize];     [_scrollviewoutlet addsubview:button];  } 

i believe need create new cgrect scratch, , assign uiview.

you cannot grab existing frame , alter it's children.

cgrect newframe = [button frame]; //this not new frame, it's existing immutable frame


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -