iphone - Can I add OBject of button to NSMutableArray? -
i trying create number of buttons on view programatically , need array, can add button object in nsmutablearray
?
yes can see following code
// create buttons sliding menu. simplicity create 5 standard buttons. nsmutablearray *buttonarray = [[nsmutablearray alloc] init]; for(nsinteger = 0; < [self.slidemenuarray count]; i++) { // rounded rect nice uibutton *btn = [uibutton buttonwithtype:uibuttontypecustom]; nsstring *title=[slidemenuarray objectatindex:i]; [btn setframe:cgrectmake(0.0f, 4.0f, 90.0f, 20.0f)]; [btn settitle:[nsstring stringwithstring:title] forstate:uicontrolstatenormal]; [btn setbackgroundcolor:[uicolor clearcolor]]; [btn settitlecolor:[uicolor whitecolor] forstate:uicontrolstatenormal]; [[btn titlelabel] setfont:[uifont systemfontofsize:12]]; [btn addtarget:self action:@selector(buttonpressed:) forcontrolevents:uicontroleventtouchupinside]; uiimage *backgroundview; if(i==0) backgroundview= [uiimage imagenamed:@"btnclk.png"]; else backgroundview= [uiimage imagenamed:@"btn.png"]; [btn setbackgroundimage:backgroundview forstate:uicontrolstatenormal]; [buttonarray addobject:btn]; }
you can retrieve added button objects this-
for(int = 0; < [buttonarray count]; i++) { uibutton *btn = [buttonarray objectatindex:i]; // move buttons position in x-demension (horizontal). cgrect btnrect = btn.frame; btnrect.origin.x = totalbuttonwidth; [btn setframe:btnrect]; }
Comments
Post a Comment