当前位置: 代码迷 >> 综合 >> 【IOS 开发学习总结-OC-54】★★ios开发UI 控件——UINavigationBar 与UINavigationController
  详细解决方案

【IOS 开发学习总结-OC-54】★★ios开发UI 控件——UINavigationBar 与UINavigationController

热度:38   发布时间:2024-01-19 01:26:45.0

【IOS 开发学习总结-OC-54】★★ios开发UI 控件——UINavigationBar 与UINavigationController

UINavigationController是个控制器,用户交互行为主要靠UINavigationBar来完成。

UINavigationBar

UINavigationBar——通常位于屏幕顶端,继承了 UIView 控件,通常只是作为多个UINavigationItem 的容器。它通过 stack (栈)的形式管理多个UINavigationItem,所以每次UINavigationBar上只能看到一个UINavigationItem对象。 它们二者的关系如下图:
这里写图片描述

UINavigationBar中的属性和方法有:

NS_CLASS_AVAILABLE_IOS(2_0) @interface UINavigationBar : UIView <NSCoding, UIBarPositioning> @property(nonatomic,assign) UIBarStyle barStyle;
@property(nullable,nonatomic,weak) id<UINavigationBarDelegate> delegate;@property(nonatomic,assign,getter=isTranslucent) BOOL translucent NS_AVAILABLE_IOS(3_0) UI_APPEARANCE_SELECTOR; // Default is NO on iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent(黑色透明)// Pushing a navigation item displays the item's title in the center of the navigation bar.
// The previous top navigation item (if it exists) is displayed as a "back" button on the left.
- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated;
//将一个pushNavigationItem压入UINavigationBar 的栈中。- (nullable UINavigationItem *)popNavigationItemAnimated:(BOOL)animated; 
//将UINavigationBar栈顶的UINavigationItem弹出
// Returns the item that was popped.@property(nullable, nonatomic,readonly,strong) UINavigationItem *topItem;
//返回最顶层的UINavigationItem控件@property(nullable, nonatomic,readonly,strong) UINavigationItem *backItem;
//返回UINavigationItem控件最顶层下面的UINavigationItem控件@property(nullable,nonatomic,copy) NSArray<UINavigationItem *> *items;
//返回UINavigationBar包含的多个UINavigationItem控件- (void)setItems:(nullable NSArray<UINavigationItem *> *)items animated:(BOOL)animated; 
// 同时为UINavigationBar设置多个UINavigationItem控件
// If animated is YES, then simulate a push or pop depending on whether the new top item was previously in the stack.@property(null_resettable, nonatomic,strong) UIColor *tintColor;//着色@property(nullable, nonatomic,strong) UIColor *barTintColor NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR;  //导航栏着色 default is nil- (void)setBackgroundImage:(nullable UIImage *)backgroundImage forBarPosition:(UIBarPosition)barPosition barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR;
//通过导航栏位置和量度设置背景图片 官方注解:Sets the background image to use for a given bar position and set of metrics(指标,度量).- (nullable UIImage *)backgroundImageForBarPosition:(UIBarPosition)barPosition barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR;
//通过导航栏位置和量度获取背景图片- (void)setBackgroundImage:(nullable UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
//通过导航栏量度设置背景图片- (nullable UIImage *)backgroundImageForBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
//通过导航栏量度获取背景图片@property(nullable, nonatomic,strong) UIImage *shadowImage NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;//阴影图片@property(nullable,