-(void) Createmeunview
{
UIButton *showmeunviewbutton = [[UIButton alloc]initwithframe:cgrectmake (0, 0, 100, 40)];
Showmeunviewbutton.center = Self.view.center;
[Showmeunviewbutton settitle:@ "Display menu" forstate:uicontrolstatenormal];
[Showmeunviewbutton Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal];
[Showmeunviewbutton Settitlecolor:[uicolor Lightgraycolor] forstate:uicontrolstateselected];
[Showmeunviewbutton addtarget:self Action: @selector (showmeunviewbuttonaction:) forControlEvents: UIControlEventTouchUpInside];
[Self.view Addsubview:showmeunviewbutton];
Showmeunview = [Self Createmeunview:showmeunviewbutton buttontitles:@[@ "1", @ "2", @ "3", @ "4", @ "5"] Menubuttontagstart : 300];
[Self.view Addsubview:showmeunview];
}
-(void) Showmeunviewbuttonaction: (UIButton *) button
{
button.selected =!button.selected;
if (button.selected) {
Showmeunview.hidden = NO;
}else
{
Showmeunview.hidden = YES;
}
}
#pragma mark--encapsulates the method of creating menus
-(UIView *) Createmeunview: (UIButton *) button buttontitles: (Nsarray *) buttontitles Menubuttontagstart: (NSInteger) Tagstart
{
The button menu appears below this parameter, the Buttontitles menu button's caption array, the Tagstart menu button tag Start value is used to distinguish which button is clicked
UIView *menuview = [[UIView alloc]initwithframe:cgrectmake (Button.minx, Button.maxy, Button.width, 41 * Buttontitles.count)];
Menuview.hidden = YES;
Menuview.backgroundcolor = [Uicolor blackcolor];
for (int i = 0; i < Buttontitles.count; i++)
{
UIButton *menubutton = [[UIButton alloc]initwithframe:cgrectmake (0, * I, Menuview.width, 40)];
Menubutton.backgroundcolor = [Uicolor Browncolor];
[Menubutton Settitle:buttontitles[i] forstate:uicontrolstatenormal];
MenuButton.titleLabel.font = font (14);
[Menubutton Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal];
[Menubutton addtarget:self Action: @selector (menubuttonaction:) forcontrolevents:uicontroleventtouchupinside];
Menubutton.tag = Tagstart + i;
[Menuview Addsubview:menubutton];
}
return menuview;
}
-(void) Menubuttonaction: (UIButton *) button
{
NSLog (@ "%lu", Button.tag);
}