Nenhuma Descrição

WMMenuView.h 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // WMMenuView.h
  3. // WMPageController
  4. //
  5. // Created by Mark on 15/4/26.
  6. // Copyright (c) 2015年 yq. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "WMMenuItem.h"
  10. #import "WMProgressView.h"
  11. #define WMUNDEFINED_VALUE -1
  12. @class WMMenuView;
  13. typedef NS_ENUM(NSUInteger, WMMenuViewStyle) {
  14. WMMenuViewStyleDefault, // 默认
  15. WMMenuViewStyleLine, // 带下划线 (若要选中字体大小不变,设置选中和非选中大小一样即可)
  16. WMMenuViewStyleTriangle, // 三角形 (progressHeight 为三角形的高, progressWidths 为底边长)
  17. WMMenuViewStyleFlood, // 涌入效果 (填充)
  18. WMMenuViewStyleFloodHollow, // 涌入效果 (空心的)
  19. WMMenuViewStyleSegmented, // 涌入带边框,即网易新闻选项卡
  20. };
  21. // 原先基础上添加了几个方便布局的枚举,更多布局格式可以通过设置 `itemsMargins` 属性来自定义
  22. // 以下布局均只在 item 个数较少的情况下生效,即无法滚动 MenuView 时.
  23. typedef NS_ENUM(NSUInteger, WMMenuViewLayoutMode) {
  24. WMMenuViewLayoutModeScatter, // 默认的布局模式, item 会均匀分布在屏幕上,呈分散状
  25. WMMenuViewLayoutModeLeft, // Item 紧靠屏幕左侧
  26. WMMenuViewLayoutModeRight, // Item 紧靠屏幕右侧
  27. WMMenuViewLayoutModeCenter, // Item 紧挨且居中分布
  28. };
  29. @protocol WMMenuViewDelegate <NSObject>
  30. @optional
  31. - (BOOL)menuView:(WMMenuView *)menu shouldSelesctedIndex:(NSInteger)index;
  32. - (void)menuView:(WMMenuView *)menu didSelectedIndex:(NSInteger)index currentIndex:(NSInteger)currentIndex;
  33. - (CGFloat)menuView:(WMMenuView *)menu widthForItemAtIndex:(NSInteger)index;
  34. - (CGFloat)menuView:(WMMenuView *)menu itemMarginAtIndex:(NSInteger)index;
  35. - (CGFloat)menuView:(WMMenuView *)menu titleSizeForState:(WMMenuItemState)state atIndex:(NSInteger)index;
  36. - (UIColor *)menuView:(WMMenuView *)menu titleColorForState:(WMMenuItemState)state atIndex:(NSInteger)index;
  37. - (void)menuView:(WMMenuView *)menu didLayoutItemFrame:(WMMenuItem *)menuItem atIndex:(NSInteger)index;
  38. @end
  39. @protocol WMMenuViewDataSource <NSObject>
  40. @required
  41. - (NSInteger)numbersOfTitlesInMenuView:(WMMenuView *)menu;
  42. - (NSString *)menuView:(WMMenuView *)menu titleAtIndex:(NSInteger)index;
  43. @optional
  44. /**
  45. * 角标 (例如消息提醒的小红点) 的数据源方法,在 WMPageController 中实现这个方法来为 menuView 提供一个 badgeView
  46. 需要在返回的时候同时设置角标的 frame 属性,该 frame 为相对于 menuItem 的位置
  47. *
  48. * @param index 角标的序号
  49. *
  50. * @return 返回一个设置好 frame 的角标视图
  51. */
  52. - (UIView *)menuView:(WMMenuView *)menu badgeViewAtIndex:(NSInteger)index;
  53. /**
  54. * 用于定制 WMMenuItem,可以对传出的 initialMenuItem 进行修改定制,也可以返回自己创建的子类,需要注意的是,此时的 item 的 frame 是不确定的,所以请勿根据此时的 frame 做计算!
  55. 如需根据 frame 修改,请使用代理
  56. *
  57. * @param menu 当前的 menuView,frame 也是不确定的
  58. * @param initialMenuItem 初始化完成的 menuItem
  59. * @param index Item 所属的位置;
  60. *
  61. * @return 定制完成的 MenuItem
  62. */
  63. - (WMMenuItem *)menuView:(WMMenuView *)menu initialMenuItem:(WMMenuItem *)initialMenuItem atIndex:(NSInteger)index;
  64. @end
  65. @interface WMMenuView : UIView <WMMenuItemDelegate>
  66. @property (nonatomic, strong) NSArray *progressWidths;
  67. @property (nonatomic, weak) WMProgressView *progressView;
  68. @property (nonatomic, assign) CGFloat progressHeight;
  69. @property (nonatomic, assign) WMMenuViewStyle style;
  70. @property (nonatomic, assign) WMMenuViewLayoutMode layoutMode;
  71. @property (nonatomic, assign) CGFloat contentMargin;
  72. @property (nonatomic, strong) UIColor *lineColor;
  73. @property (nonatomic, assign) CGFloat progressViewBottomSpace;
  74. @property (nonatomic, weak) id<WMMenuViewDelegate> delegate;
  75. @property (nonatomic, weak) id<WMMenuViewDataSource> dataSource;
  76. @property (nonatomic, weak) UIView *leftView;
  77. @property (nonatomic, weak) UIView *rightView;
  78. @property (nonatomic, copy) NSString *fontName;
  79. @property (nonatomic, weak) UIScrollView *scrollView;
  80. /** 进度条的速度因数,默认为 15,越小越快, 大于 0 */
  81. @property (nonatomic, assign) CGFloat speedFactor;
  82. @property (nonatomic, assign) CGFloat progressViewCornerRadius;
  83. @property (nonatomic, assign) BOOL progressViewIsNaughty;
  84. @property (nonatomic, assign) BOOL showOnNavigationBar;
  85. - (void)slideMenuAtProgress:(CGFloat)progress;
  86. - (void)selectItemAtIndex:(NSInteger)index;
  87. - (void)resetFrames;
  88. - (void)reload;
  89. - (void)updateTitle:(NSString *)title atIndex:(NSInteger)index andWidth:(BOOL)update;
  90. - (void)updateAttributeTitle:(NSAttributedString *)title atIndex:(NSInteger)index andWidth:(BOOL)update;
  91. - (WMMenuItem *)itemAtIndex:(NSInteger)index;
  92. /// 立即刷新 menuView 的 contentOffset,使 title 居中
  93. - (void)refreshContenOffset;
  94. - (void)deselectedItemsIfNeeded;
  95. /**
  96. * 更新角标视图,如要移除,在 -menuView:badgeViewAtIndex: 中返回 nil 即可
  97. */
  98. - (void)updateBadgeViewAtIndex:(NSInteger)index;
  99. @end