All Products
Search
Document Center

Custom navigation bar

Last Updated: May 21, 2021

AUCustomNavigationBar is a navigation bar component customized by mPaaS for the transparent navigation bar scenario.

After the native navigation bar is changed from transparent to solid, users may have bad visual experience. This class is provided for avoiding this issue.

Sample image

API description

 
  1. /**
  2. Customize a transparent navigation bar as required.
  3. After the native navigation pane is changed from transparent to solid, users may have bad visual experience. This class is provided for avoiding this issue.
  4. */
  5. @interface AUCustomNavigationBar : UIView
  6. @property(nonatomic, strong) UIView *backgroundView; // Ground glass background view.
  7. @property(nonatomic, strong) NSString *backButtonTitle; // The back button title (no title by default).
  8. @property(nonatomic, strong) UIColor *backButtonTitleColor; // The title color of the back button.
  9. @property(nonatomic, strong) UIImage *backButtonImage; // The image of the back button.
  10. @property(nonatomic, strong) NSString *title; // The title.
  11. @property(nonatomic, strong) UIColor *titleColor; // The title color.
  12. @property(nonatomic, strong) UIView *titleView; // Customized titleview.
  13. @property(nonatomic, strong) NSString *rightItemTitle; // The right item title.
  14. @property(nonatomic, strong) UIColor *rightItemTitleColor; // The color of the right item title.
  15. @property(nonatomic, strong) UIImage *rightItemImage; // The image of the right item.
  16. /**
  17. * The VoiceOver text for the item displayed on the right.
  18. * The item displayed on the left, which is "Back" by default.
  19. * The item displayed on the right, which is specified by rightItemTitle by default. If rightItemTitle is not set, manually set this property to support VoiceOver.
  20. */
  21. @property(nonatomic,strong) NSString *rightItemVoiceOverText;
  22. @property(nonatomic,strong) NSString *leftItemVoiceOverText;
  23. /**
  24. * Create a specified view of transparent navigation bar.
  25. *
  26. * (1) By default, the navigation bar displays an arrow instead of "Back" on the left for users to go back. If the current page needs to set the back text that is consistent with the framework logic, override the (UIView *)customNavigationBar method in VC.
  27. * (2) To set the title, item to be displayed on the right, and background in frosted glass effect, call related APIs.
  28. *
  29. * @param currentVC The current VC.
  30. *
  31. * @return The view of transparent navigation bar.
  32. */
  33. + (AUCustomNavigationBar *)navigationBarForCurrentVC:(UIViewController *)currentVC;
  34. /**
  35. * Set the background view of frosted glass. The transparency is 0 by default.
  36. */
  37. - (void)setNavigationBarBlurEffective;
  38. /**
  39. * Create an item to be displayed on the right of the navigation bar.
  40. *
  41. * @param rightItemTitle Displayed text.
  42. * @param target target
  43. * @param action action
  44. *
  45. */
  46. - (void)setNavigationBarRightItemWithTitle:(NSString *)rightItemTitle target:(id)target action:(SEL)action;
  47. /**
  48. * Create an item to be displayed on the right of the navigation bar.
  49. *
  50. * @param rightItemImage Displayed image.
  51. * @param target target
  52. * @param action action
  53. *
  54. */
  55. - (void)setNavigationBarRightItemWithImage:(UIImage *)rightItemImage target:(id)target action:(SEL)action;
  56. /**
  57. * Create an item to be displayed on the left of the navigation bar.
  58. *
  59. * @param leftItemTitle Displayed text.
  60. * @param target target
  61. * @param action action
  62. *
  63. */
  64. - (void)setNavigationBarLeftItemWithTitle:(NSString *)leftItemTitle target:(id)target action:(SEL)action;
  65. /**
  66. * Create an item to be displayed on the left of the navigation bar.
  67. *
  68. * @param leftItemTitle Displayed image.
  69. * @param target target
  70. * @param action action
  71. *
  72. */
  73. - (void)setNavigationBarLeftItemWithImage:(UIImage *)leftItemTitle target:(id)target action:(SEL)action;
  74. @end

Sample code

 
  1. AUCustomNavigationBar *navBar = [AUCustomNavigationBar navigationBarForCurrentVC:self];
  2. [navBar setNavigationBarBlurEffective]; // The frosted glass effect.
  3. [self.view addSubview:navBar];
  4. navBar.title = @"Title";
  5. navBar.backButtonImage = [AUIconView iconWithName:kICONFONT_BILL width:22 color:AU_COLOR_LINK];
  6. navBar.backButtonTitle = @"Bill";
  7. navBar.rightItemImage = [AUIconView iconWithName:kICONFONT_ADD width:22 color:AU_COLOR_LINK];
  8. // When using this API on mPaaS, override the following methods of the parent class:
  9. - (BOOL)autohideNavigationBar
  10. {
  11. return YES;
  12. }
  13. - (UIView *)customNavigationBar
  14. {
  15. return self.navBar;
  16. }