你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS:UINavigationController的常用屬性

iOS:UINavigationController的常用屬性

編輯:IOS開發綜合
//從當前視圖push到目標視圖,如果視圖已經存在,則不影響堆棧
[self.navigationController pushViewController:commentListVC animated:YES];
//返回上一控制器
[self.navigationController popViewControllerAnimated:YES];
//返回某一控制器
[self.navigationController popToViewController:[[UIViewController alloc] init] animated:YES];
//返回到根視圖
[self.navigationController popToRootViewControllerAnimated:YES];
//B pop 返回A後,B是否釋放要看之後的代碼是否再次使用了B,如果後面的代碼還使用到了B,則B所占的內存一直保留,有一種情況例外,在內存極度不足的情況下,IOS會遵從一定的策略有可能把B釋放,B再次被使用的時候再重新創建
另外,即使pop後後面的代碼不再使用B了,那麼B的內存只是有可能被釋放,釋放的時機並不一定,這取決於垃圾回收器的回收策略

//去掉返回按鈕的文字顯示
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:NULL];

//自定義左右導航項一
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
UIBarButtonItem *bar1 = [[UIBarButtonItem alloc] initWithCustomView:btn1];
UIBarButtonItem *bar2 = [[UIBarButtonItem alloc] initWithCustomView:btn2];
//導航欄的左右導航項,可以自定義button
self.navigationItem.leftBarButtonItem = bar1;
self.navigationItem.rightBarButtonItem = bar1;
//也可以添加多個,後面跟數組,排列順序是依次排列
self.navigationItem.leftBarButtonItems = @[bar1,bar2];
self.navigationItem.rightBarButtonItems = @[bar1,bar2];
//自定義左右導航項二
viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navItem_course"] style:UIBarButtonItemStylePlain target:self action:@selector(showCourse:)];
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注銷" style:UIBarButtonItemStylePlain target:self action:@selector(logOut:)];

//設置導航欄的標題視圖,可以自定義一個view,label都可以
self.navigationItem.titleView
// back 按鈕背景為白色
[self.navigationBar setTintColor:[UIColor whiteColor]];
[self.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:COLOR_WITH_RGB(230, 230, 230), UITextAttributeTextColor,[UIFont boldSystemFontOfSize:18.0f],UITextAttributeFont, nil]];
//設置導航欄顏色
[self.navigationBar setBackgroundImage:[UIImage imageWithColor:COLOR_WITH_RGB(70, 70, 70) size:CGSizeMake(SCREEN_WIDTH, KNav_Height)] forBarMetrics:UIBarMetricsDefault];
//隱藏navigationBar
self.navigationController.navigationBarHidden = YES;

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved