标签:
//创建一个导航栏 UINavigationBar *navigationBar=[[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; //创建一个导航栏集合 UINavigationItem *navigationItem=[[UINavigationItem alloc] initWithTitle:nil]; //创建一个导航栏的左边的按钮 UIBarButtonItem *leftbutton=[[UIBarButtonItem alloc] initWithTitle:@"左边" style:UIBarButtonItemStyleBordered target:self action:@selector(dosomething)]; //创建一个导航栏的右边的按钮 UIBarButtonItem *rightbutton=[[UIBarButtonItem alloc] initWithTitle:@"右边" style:UIBarButtonItemStyleBordered target:self action:@selector(dosomething)]; [navigationItem setTitle:@"导航栏"]; //向导航栏集合添加 左右两边的按钮 [navigationItem setLeftBarButtonItem:leftbutton]; [navigationItem setRightBarButtonItem:rightbutton]; //把导航栏集合 添加到 导航栏中 [navigationBar pushNavigationItem:navigationItem animated:NO]; //视图添加导航栏 [self.view addSubview:navigationBar];
运行结果如下:
标签:
原文地址:http://www.cnblogs.com/xieyier/p/4182010.html