objective c - Can't see the button -
- (void)viewdidload{ int leftborder = 80; int topborder = 160; int width = 150; int height = 50; uiview *myview = [[uiview alloc] initwithframe:cgrectmake(leftborder, topborder, width, height)]; myview.layer.cornerradius = 5; myview.backgroundcolor = [uicolor redcolor]; [self.view addsubview:myview]; uibutton *testbutton = [uibutton buttonwithtype:uibuttontyperoundedrect]; testbutton.frame = cgrectmake(0, 0, 50, 50); [testbutton settitle:@"testbutton" forstate:uicontrolstatenormal]; [testbutton addtarget:self action:@selector(buttonclicked:) forcontrolevents:uicontroleventtouchupinside]; [self.myview addsubview:self.testbutton]; self.myview.hidden = yes; [super viewdidload]; }
hi, sorry stupid question! i'm newby in xcode. why didn't see button? , how can hide button after click? need button inside frame.
simple remove self.myview.hidden = yes;
to add click listener, 2 solution:
by code in viewdidload:
- (void)viewdidload { [super viewdidload]; [mybutton addtarget:self action:@selector(mybuttonclick:) forcontrolevents:(uicontrolevents)uicontroleventtouchdown]; } - (void)mybuttonclick:(id)sender { mybutton.hidden = yes; }
or via interface builder (preferred), easiest way define handler/action in xcode using ibaction declaration in interface file (add declaration before @end statement). attach action button
Comments
Post a Comment