標籤:
首先需要子類化一個navigationController的子類,在init方法中對定製nav的一些基本需求進行設定
1 - (instancetype)initWithRootViewController:(UIViewController *)rootViewController 2 { 3 if (self = [super initWithRootViewController:rootViewController]) { 4 // 設定navigationBar的背景顏色,根據需要自己設定 5 self.navigationBar.barTintColor = redButtonColor; 6 // 設定navigationBar是否透明,不透明的話會使可用介面原點下移(0,0)點為導覽列左下角下方的那個點 7 self.navigationBar.translucent = NO; 8 // 設定navigationBar是不是使用系統預設返回,預設為YES 9 self.interactivePopGestureRecognizer.enabled = YES;10 // 建立一個顏色,便於之後設定顏色使用11 UIColor * color = [UIColor whiteColor];12 // 設定navigationBar元素的背景顏色,不包括title13 self.navigationBar.tintColor = color;14 // 設定navigationController的title的字型顏色15 NSDictionary * dict=[NSDictionary dictionaryWithObject:color forKey:NSForegroundColorAttributeName];16 self.navigationBar.titleTextAttributes = dict;17 }18 19 return self;20 }
因為這個導覽列是你自己自訂的,所以預設的側滑返回會失效,接下來要在viewDidLoad中從新遵循手勢的代理
- (void)viewDidLoad{ // 為self建立弱引用對象 __weak typeof (self) weakSelf = self; if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.interactivePopGestureRecognizer.delegate = weakSelf; }}
OK,完成
iOS7以上自訂一個navigationController,並沿用系統的側滑返回效果