UIViewController+General.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // UIViewController+General.h
  3. // AIIM
  4. //
  5. // Created by qitewei on 2025/5/5.
  6. //
  7. #import <UIKit/UIKit.h>
  8. NS_ASSUME_NONNULL_BEGIN
  9. typedef NS_ENUM(NSInteger, BarButtonItemPosition) {
  10. BarButtonItemPositionLeft,
  11. BarButtonItemPositionRight
  12. };
  13. @interface UIViewController (General)
  14. #pragma mark - Navigation Bar 基本配置
  15. /// 设置导航栏是否隐藏 (默认NO)
  16. - (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated;
  17. /// 设置导航栏是否透明 (默认NO)
  18. - (void)setNavigationBarTransparent:(BOOL)transparent;
  19. /// 设置导航栏背景颜色 (默认白色)
  20. - (void)setNavigationBarBackgroundColor:(UIColor *)color;
  21. /// 设置导航栏标题
  22. - (void)setNavigationTitle:(NSString *)title;
  23. /// 设置导航栏标题颜色和字体
  24. - (void)setNavigationTitleColor:(UIColor *)color font:(UIFont *)font;
  25. #pragma mark - 返回按钮配置
  26. /// 设置返回按钮文字 (默认"返回")
  27. - (void)setBackButtonTitle:(NSString *)title;
  28. /// 设置返回按钮图片 (默认系统返回箭头)
  29. - (void)setBackButtonImage:(UIImage *)image;
  30. /// 设置返回按钮颜色 (默认蓝色)
  31. - (void)setBackButtonColor:(UIColor *)color;
  32. /// 禁用返回手势 (默认NO)
  33. - (void)disableInteractivePopGesture:(BOOL)disable;
  34. #pragma mark - 添加自定义按钮
  35. /// 添加文字按钮
  36. - (void)addBarButtonWithTitle:(NSString *)title
  37. position:(BarButtonItemPosition)position
  38. action:(SEL)action;
  39. /// 添加图片按钮
  40. - (void)addBarButtonWithImage:(UIImage *)image
  41. position:(BarButtonItemPosition)position
  42. action:(SEL)action;
  43. /// 添加自定义视图按钮
  44. - (void)addBarButtonWithCustomView:(UIView *)view
  45. position:(BarButtonItemPosition)position;
  46. /// 移除指定位置的按钮
  47. - (void)removeBarButtonAtPosition:(BarButtonItemPosition)position;
  48. #pragma mark - 工具方法
  49. /// 返回上一级页面
  50. - (void)popViewController;
  51. /// 返回根视图
  52. - (void)popToRootViewController;
  53. @end
  54. NS_ASSUME_NONNULL_END