iphone - How can I create an array of UIButtons/(UIImageViews) that appear after the last one was pressed -


i wasn't sure how search answer question figured try luck on here.

to put in short, have uiview , created uibutton programmatically along uiimageview added button subview , happens is, when press on button, allows me add image , gets stored on button.

so question is: once completed, how can make button/imageview appear in view, next first button (or after fills screen right, appear in 2nd row, 1st column) etc

thank in advanced!

you can use uicollectionview pointed out @bernahard harrer or use following code. code adds 2 buttons. in case, need more buttons or array of buttons, implement following code , calculate size of added button, height/width of button1 calculated adding button2:

#import "viewcontroller.h"  @interface viewcontroller ()  @end  @implementation viewcontroller  - (void)viewdidload {     [super viewdidload]; // additional setup after loading view, typically nib.     [self addbuttons];  }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }   -(void) addbuttons {     uiview *view = [self view];     uibutton *button1 = [uibutton buttonwithtype:uibuttontyperoundedrect];     [button1 setbackgroundimage:[uiimage imagenamed:@"buttonimage1"] forstate:uicontrolstatenormal]; uibutton *button2 = [uibutton buttonwithtype:uibuttontyperoundedrect]; [button2 setbackgroundimage:[uiimage imagenamed:@"buttonimage2"] forstate:uicontrolstatenormal];  [button1 sizetofit]; [button2 sizetofit];   cgfloat combinedwidth = (button1.frame.size.width) + (button2.frame.size.width) ;  //checking if combined width of both buttons more 320 if (combinedwidth>320) {     cgfloat button1height = button1.frame.size.height;     button1height = button1height + 10;     [button2 setframe:cgrectmake(button2.frame.origin.x, (button2.frame.origin.y + button1height), button2.frame.size.width, button2.frame.size.width)]; } else {     //if combined width of both buttons less or equal 320     //this place buttons adjacent each other.     //the code may modified accordingly if add distance between them     cgfloat button1width = button1.frame.size.width;     [button2 setframe:cgrectmake((button1.frame.origin.x+button1width), button2.frame.origin.y, button2.frame.size.width, button2.frame.size.height)]; }  [view addsubview:button1]; [view addsubview:button2]; }@end 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -