文档

定制导航栏

更新时间:

AUCustomNavigationBar 是 mPaaS 中专门为透明导航栏定制的导航栏控件。原生的导航栏从透明切换到不透明时会有视觉体验问题,采用 AUCustomNavigationBar 能够避免此类问题。

效果图

接口说明

    /**
 自定义透明导航栏,主要用于导航栏需要透明的场景
 由于用原生的导航栏切换会有视觉体验问题,故写此类
 */
@interface AUCustomNavigationBar : UIView

@property(nonatomic, strong) UIView *backgroundView;              // 毛玻璃背景 view

@property(nonatomic, strong) NSString *backButtonTitle;           // 返回按钮 title(默认无)
@property(nonatomic, strong) UIColor *backButtonTitleColor;       // 返回按钮 title 颜色
@property(nonatomic, strong) UIImage *backButtonImage;            // 返回按钮图片

@property(nonatomic, strong) NSString *title;                     // 标题
@property(nonatomic, strong) UIColor *titleColor;                 // 标题颜色
@property(nonatomic, strong) UIView *titleView;                   // 自定义 titleview

@property(nonatomic, strong) NSString *rightItemTitle;            // 右侧 item title
@property(nonatomic, strong) UIColor *rightItemTitleColor;        // 右侧 item title 颜色
@property(nonatomic, strong) UIImage *rightItemImage;             // 右侧 item 图片

/**
 * 右侧 item 的 VoiceOver 提示文案,
 * 左侧 item 默认为“返回”
 * 右侧 item 默认是 rightItemTitle,如果没有设置 rightItemTitle,需要手动设置此属性来支持 VoiceOver
 */
@property(nonatomic,strong) NSString *rightItemVoiceOverText;

@property(nonatomic,strong) NSString *leftItemVoiceOverText;


/**
 *  创建指定透明的导航栏 View。
 *
 *  (1)此导航栏默认在左侧显示返回箭头图片,不显示返回文本。若当前页面需设置与框架逻辑一致的返回文案,请在 VC 中重写 - (UIView *)customNavigationBar 方法
 *  (2)如需设置标题、右侧 item、毛玻璃背景,请调用相关接口
 *
 *  @param currentVC 当前 VC
 *
 *  @return 透明的导航栏 View
 */
+ (AUCustomNavigationBar *)navigationBarForCurrentVC:(UIViewController *)currentVC;

/**
 *  设置毛玻璃背景 View,默认透明度为 0
 */
- (void)setNavigationBarBlurEffective;

/**
 *  创建导航栏右侧 item
 *
 *  @param rightItemTitle    显示的文本
 *  @param target            target
 *  @param action            action
 *
 */
- (void)setNavigationBarRightItemWithTitle:(NSString *)rightItemTitle target:(id)target action:(SEL)action;

/**
 *  创建导航栏右侧 item
 *
 *  @param rightItemImage    显示的图片
 *  @param target            target
 *  @param action            action
 *
 */
- (void)setNavigationBarRightItemWithImage:(UIImage *)rightItemImage target:(id)target action:(SEL)action;


/**
 *  创建导航栏左侧 item
 *
 *  @param leftItemTitle     显示的文本
 *  @param target            target
 *  @param action            action
 *
 */
- (void)setNavigationBarLeftItemWithTitle:(NSString *)leftItemTitle target:(id)target action:(SEL)action;

/**
 *  创建导航栏左侧 item
 *
 *  @param leftItemTitle     显示的图片
 *  @param target            target
 *  @param action            action
 *
 */
- (void)setNavigationBarLeftItemWithImage:(UIImage *)leftItemTitle target:(id)target action:(SEL)action;


@end

代码示例

AUCustomNavigationBar *navBar = [AUCustomNavigationBar navigationBarForCurrentVC:self];
[navBar setNavigationBarBlurEffective]; // 毛玻璃效果
[self.view addSubview:navBar];
navBar.title = @"标题";
navBar.backButtonImage = [AUIconView iconWithName:kICONFONT_BILL width:22 color:AU_COLOR_LINK];
navBar.backButtonTitle = @"账单";
navBar.rightItemImage = [AUIconView iconWithName:kICONFONT_ADD width:22 color:AU_COLOR_LINK];

// mPaaS 内使用,需覆盖父类的如下两个方法
- (BOOL)autohideNavigationBar
{
        return YES;
}
- (UIView *)customNavigationBar
{
        return self.navBar;
}
  • 本页导读 (0)
文档反馈