知識點:
1.UINavigationController
2.UINavigationItem
3.UINavigationBar
4.UINavigationController視圖切換
========================
UINavigationController
1.什麼是導航控制器
作用:管理視圖控制器
2.UINavigationController對象創立
1)初始化方式
- (id)initWithRootViewController:(UIViewController *)rootViewController
2)UINavigationController組成:
(1)navigationBar(高度44)
(2)customContent — 有自定義的ViewController提供
(3)navigationToolbar(高度44)
3.經過UINavigationController對象切換視圖
1)將視圖控制器壓入導航控制器的棧容器中
- (void)pushViewController:(UIViewController *)viewController
animated:(BOOL)animated
2)將視圖控制器從導航控制器中彈出
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
========================
UINavigationItem
UINavigationItem包括了:
(1)backBarButtonItem(由上一級ctl的屬性決議)
(2)title/titleView(以後ctl)
(3)rightBarButtonItem(以後ctl)
(4)leftBarButtonItem(以後ctl)
1.UINavigationItem和UIViewController關系
navigationItem是UIViewController的一個屬性
這個屬性是為UINavigationController服務的
2.創立UIBarButtonItem
1)創立零碎自帶的UIBarButtonSystemItem
- (id)initWithBarButtonSystemItem:(UIBarButtonSystemItem)systemItem
target:(id)target
action:(SEL)action;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(btnAction)];
2)文字UIBarButtonItem的創立方式
- (id)initWithTitle:(NSString *)title
style:(UIBarButtonItemStyle)style
target:(id)target
action:(SEL)action
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem new];
3)圖片UIBarButtonItem的創立方式
- (id)initWithImage:(UIImage *)image
style:(UIBarButtonItemStyle)style
target:(id)target
action:(SEL)action
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"refresh_30"] style:UIBarButtonItemStylePlain target:nil action:nil];
3)如何將UIBarButtonItem參加到導航的右邊和左邊
@property (nonatomic, retain) UIBarButtonItem *leftBarButtonItem
@property (nonatomic, retain) UIBarButtonItem *rightBarButtonItem
@property (nonatomic, retain) UIBarButtonItem *backBarButtonItem
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:b];
3.定制UIBarButtonItem
4.定制導航兩頭的titleView
self.navigationItem.title = @"控制器2";
5.定制backBarButtonItem
留意:設置以後控制器的backBarButtonItem需求在下一個控制器中才干顯示
========================
UINavigationBar
1.如何往UINavigationBar貼圖
設置背景圖片
- (void)setBackgroundImage:(UIImage *)backgroundImage
forBarMetrics:(UIBarMetrics)barMetrics
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"1.png"] forBarMetrics:UIBarMetricsDefault];
2.如何設置UINavigationBar設置顏色
@property (nonatomic, retain) UIColor *tintColor
@property (nonatomic, retain) UIColor *barTintColor
3.如何設置通明顏色
1)設置UINavigationBar的款式
@property (nonatomic, assign) UIBarStyle barStyle
self.navigationController.navigationBar.barStyle= UIBarStyleBlack;
2)能否通明
@property (nonatomic, assign, getter=isTranslucent) BOOL translucent
//獲取管理應前視圖控制器的導航控制器(假如這個視圖控制器沒有遭到導航控制器管理,此辦法會前往空指針)
//設置導航欄為不通明,坐標點會自動下移64個單位
self.navigationController.navigationBar.translucent = NO;
3)改動導航欄的顏色
@property(nonatomic,retain) UIColor *barTintColor
//設置背風光
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0];
4.如何隱藏UINavigationBar
1)不帶動畫隱藏
@property (nonatomic, getter=isNavigationBarHidden) BOOL navigationBarHidden
//顯示
self.navigationController.navigationBarHidden = NO;
2)帶動畫隱藏
- (void) setNavigationBarHidden:(BOOL)navigationBarHidden
animated:(BOOL)animated
[self.navigationController setNavigationBarHidden:YES animated:YES];
========================
UINavigationController視圖切換
1.獲取導航控制器中的視圖數組
@property (nonatomic, copy) NSArray *viewControllers
2.將視圖控制器壓入導航控制器的棧容器中
- (void)pushViewController:(UIViewController *)viewController
animated:(BOOL)animated
//視圖控制器入棧
[self.navigationController pushViewController:ctlA animated:YES];
3.將視圖控制器從導航控制器中彈出
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
4.切換至指定的視圖控制器(該控制器必需在以後導航控制器中的棧中)
- (NSArray *)popToViewController:(UIViewController *)viewController
animated:(BOOL)animated
5.回到根視圖控制器
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated
【iOS開發-UI (六)Navigation】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!