本文實例為年夜家分享了IOS下拉菜單的詳細代碼,供年夜家參考,詳細內容以下
1、後果圖
2、工程圖
3、代碼
RootViewController.h
#import <UIKit/UIKit.h> @interface RootViewController : UIViewController @end
RootViewController.m
#import "RootViewController.h" #import "NIDropDown.h" @interface RootViewController () @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title=@"DropDown"; UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame=CGRectMake(10, 100, 150,30); button.backgroundColor=[UIColor redColor]; [button addTarget:self action:@selector(doClickAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } -(void)doClickAction:(UIButton *)btn { NSArray *dataArray=[NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5", nil]; NIDropDown *dropDown=[[NIDropDown alloc]init]; [dropDown showDropDown:btn andHeight:[dataArray count]*36 andData:dataArray]; [self.view addSubview:dropDown]; }
以上就是本文的全體內容,願望對年夜家的進修有所贊助,也願望年夜家多多支撐本站。
【IOS代碼筆記之下拉菜單後果】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!