iphone - Subview with UIButton isn't clickable -
here's code i'm working with:
uibutton *mainbutton = [[uibutton alloc] initwithframe:cgrectmake(0, 0, 100, 100)]; [mainbutton setimage:[uiimage imagenamed:@"circleshape.png"] forstate:uicontrolstatenormal]; mainbutton.center = cgpointmake(self.view.frame.size.width/2.0f, self.view.frame.size.height/2.0f); [self.view addsubview:mainbutton]; uiview *subview = [[uiview alloc] initwithframe:cgrectmake(0, 100, 200, 100)]; [subview setbackgroundcolor:[uicolor purplecolor]]; [mainbutton addsubview:subview]; uibutton *secondbutton = [[uibutton alloc] initwithframe:cgrectmake(0, 0, 100, 100)]; [secondbutton setimage:[uiimage imagenamed:@"circleshape.png"] forstate:uicontrolstatenormal]; secondbutton.center = cgpointmake(subview.frame.size.width/2.0f, subview.frame.size.height/2.0f); [subview addsubview:secondbutton];
why mainbutton clickable secondbutton isn't?
k should add sub view on self.view.
uiview *subview = [[uiview alloc] initwithframe:cgrectmake(0, 100, 200, 100)]; [subview setbackgroundcolor:[uicolor purplecolor]]; [self.view addsubview:subview]; uibutton *secondbutton = [[uibutton alloc] initwithframe:cgrectmake(0, 0, 100, 100)]; [secondbutton setimage:[uiimage imagenamed:@"circleshape.png"] forstate:uicontrolstatenormal]; secondbutton.center = cgpointmake(subview.frame.size.width/2.0f, subview.frame.size.height/2.0f); [subview addsubview:secondbutton]; uibutton *thirdbutton = [[uibutton alloc] initwithframe:cgrectmake(100, 0, 100, 100)]; [secondbutton setimage:[uiimage imagenamed:@"circleshape.png"] forstate:uicontrolstatenormal]; secondbutton.center = cgpointmake(subview.frame.size.width/2.0f, subview.frame.size.height/2.0f); [subview addsubview:secondbutton];
try this. add 2 buttons on subview.
Comments
Post a Comment