IOS导航栏的使用方法
简介:
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
//创建一个导航栏集合
UINavigationItem *na...
- UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
-
- UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:nil];
-
-
-
-
- UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"左边" style:UIBarButtonItemStyleBordered target:self action:@selector(clickLeftButton)];
-
- UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"右边" style:UIBarButtonItemStyleDone target:self action:@selector(clickRightButton)];
-
-
- [navItem setTitle:@"图灵工作室"];
-
-
- [navBar pushNavigationItem:navItem animated:NO];
-
-
- [navItem setLeftBarButtonItem:leftButton];
- [navItem setRightBarButtonItem:rightButton];
-
-
- [self.view addSubview:navBar];
- -(void)showDialog:(NSString *)str
- {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"这是一个对话框" message:str delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
- [alert show];
-
- }
-
- -(void) clickLeftButton
- {
- [self showDialog:@"点击了导航栏左边按钮"];
- }
-
- -(void) clickRightButton
- {
- [self showDialog:@"点击了导航栏右边按钮"];
- }