@@ -33,14 +33,14 @@ typedef NS_ENUM(NSInteger, SPPageMenuTrackerFollowingMode) {
3333};
3434
3535typedef NS_ENUM (NSInteger , SPItemImagePosition) {
36- SPItemImagePositionDefault, // 默认图片在左边
37- SPItemImagePositionLeft, // 图片在左边
38- SPItemImagePositionTop , // 图片在上面
39- SPItemImagePositionRight , // 图片在右边
40- SPItemImagePositionBottom // 图片在下面
36+ SPItemImagePositionDefault, // 默认图片在左侧
37+ SPItemImagePositionLeft, // 图片在文字左侧
38+ SPItemImagePositionRight , // 图片在文字右侧
39+ SPItemImagePositionTop , // 图片在文字上侧
40+ SPItemImagePositionBottom // 图片在文字下侧
4141};
4242
43- @class SPPageMenu;
43+ @class SPPageMenu,SPPageMenuButtonItem ;
4444
4545@protocol SPPageMenuDelegate <NSObject >
4646
@@ -62,7 +62,7 @@ typedef NS_ENUM(NSInteger, SPItemImagePosition) {
6262/* *
6363 * 传递数据
6464 *
65- * @param items 数组 (数组元素只能是NSString或UIImage类型 )
65+ * @param items 数组 (数组元素可以是NSString、UIImage类型、SPPageMenuButtonItem类型,其中SPPageMenuButtonItem相当于一个模型,可以同时设置图片和文字 )
6666 * @param selectedItemIndex 默认选中item的下标
6767 */
6868- (void )setItems : (nullable NSArray *)items selectedItemIndex : (NSInteger )selectedItemIndex ;
@@ -71,6 +71,12 @@ typedef NS_ENUM(NSInteger, SPItemImagePosition) {
7171
7272@property (nonatomic ,readonly ) NSUInteger numberOfItems; // items的总个数
7373
74+ #if TARGET_INTERFACE_BUILDER
75+ @property (nonatomic , readonly ) IBInspectable NSInteger trackerStyle; // 该枚举属性支持storyBoard/xib,方便在storyBoard/xib中创建时直接设置
76+ #else
77+ @property (nonatomic , readonly ) SPPageMenuTrackerStyle trackerStyle;
78+ #endif
79+
7480// item之间的间距,默认30;当排列方式permutationWay为‘SPPageMenuPermutationWayNotScrollAdaptContent’时此属性无效,无效是合理的,不可能做到“不可滑动且自适应内容”然后间距又自定义,这2者相互制约;
7581@property (nonatomic , assign ) CGFloat itemPadding;
7682
@@ -110,11 +116,15 @@ typedef NS_ENUM(NSInteger, SPItemImagePosition) {
110116@property (nonatomic ) CGFloat selectedItemZoomScale;
111117@property (nonatomic , assign ) BOOL needTextColorGradients; // 是否需要文字渐变,默认为YES
112118
119+ @property (nonatomic , assign ) BOOL showFuntionButton; // 是否显示功能按钮(功能按钮显示在最右侧),默认为NO
120+ @property (nonatomic , assign ) CGFloat funtionButtonshadowOpacity; // 功能按钮左侧的阴影透明度,如果设置小于等于0,则没有阴影
121+
113122@property (nonatomic , weak ) id <SPPageMenuDelegate> delegate;
114123
115124// 插入item,插入和删除操作时,如果itemIndex超过了了items的个数,则不做任何操作
116125- (void )insertItemWithTitle : (nullable NSString *)title atIndex : (NSUInteger )itemIndex animated : (BOOL )animated ;
117- - (void )insertItemWithImage : (nullable UIImage *)image atIndex : (NSUInteger )itemIndex animated : (BOOL )animated ;
126+ - (void )insertItemWithImage : (nullable UIImage *)image atIndex : (NSUInteger )itemIndex animated : (BOOL )animated ;
127+ - (void )insertItem : (nullable SPPageMenuButtonItem *)item atIndex : (NSUInteger )itemIndex animated : (BOOL )animated ;
118128// 如果移除的正是当前选中的item(当前选中的item下标不为0),删除之后,选中的item会切换为上一个item
119129- (void )removeItemAtIndex : (NSUInteger )itemIndex animated : (BOOL )animated ;
120130- (void )removeAllItems ;
@@ -125,6 +135,11 @@ typedef NS_ENUM(NSInteger, SPItemImagePosition) {
125135- (void )setImage : (nullable UIImage *)image forItemAtIndex : (NSUInteger )itemIndex ; // 设置指定item的图片,设置后,仅会有图片
126136- (nullable UIImage *)imageForItemAtIndex : (NSUInteger )itemIndex ; // 获取指定item的图片
127137
138+ - (void )setItem : (SPPageMenuButtonItem *)item forItemIndex : (NSUInteger )itemIndex ; // 同时为指定item设置标题和图片,其中参数item相当于一个模型,可以同时设置文字和图片
139+ - (nullable SPPageMenuButtonItem *)itemAtIndex : (NSUInteger )itemIndex ; // 获取指定item
140+
141+ - (id )objectForItemAtIndex : (NSUInteger )itemIndex ; // 获取指定item,该方法获取的item可能是NSString、UIImage或SPPageMenuButtonItem类型
142+
128143- (void )setWidth : (CGFloat)width forItemAtIndex : (NSUInteger )itemIndex ; // 设置指定item的宽度(如果width为0,item会根据内容自动计算width)
129144- (CGFloat)widthForItemAtIndex : (NSUInteger )itemIndex ; // 获取指定item的宽度
130145
@@ -138,33 +153,8 @@ typedef NS_ENUM(NSInteger, SPItemImagePosition) {
138153- (void )setBackgroundImage : (nullable UIImage *)backgroundImage barMetrics : (UIBarMetrics)barMetrics ;
139154- (nullable UIImage *)backgroundImageForBarMetrics : (UIBarMetrics)barMetrics ; // 获取背景图片
140155
141- /* *
142- 同时为指定item设置标题和图片
143-
144- @param title 标题
145- @param image 图片
146- @param imagePosition 图片的位置,分上、左、下、右
147- @param ratio 图片所占item的比例,图片在左右时默认0.5,图片在上下时默认2.0/3.0
148- @param imageTitleSpace 图片与标题之间的间距,默认0
149- @param itemIndex item的下标
150- */
151- - (void )setTitle : (nullable NSString *)title image : (nullable UIImage *)image imagePosition : (SPItemImagePosition)imagePosition imageRatio : (CGFloat)ratio imageTitleSpace : (CGFloat)imageTitleSpace forItemIndex : (NSUInteger )itemIndex ;
152-
153-
154- @property (nonatomic , assign ) BOOL showFuntionButton; // 是否显示功能按钮(功能按钮显示在最右侧),默认为NO
155- @property (nonatomic , assign ) CGFloat funtionButtonshadowOpacity; // 功能按钮左侧的阴影透明度,如果设置小于等于0,则没有阴影
156-
157- /* *
158- * 同时为functionButton设置标题和图片
159- *
160- * @param title 标题
161- * @param image 图片
162- * @param imagePosition 图片的位置,分上、左、下、右
163- * @param ratio 图片所占item的比例,图片在左右时默认0.5,图片在上下时默认2.0/3.0
164- * @param imageTitleSpace 图片与标题之间的间距,默认0
165- * @param state 控件状态
166- */
167- - (void )setFunctionButtonTitle : (nullable NSString *)title image : (nullable UIImage *)image imagePosition : (SPItemImagePosition)imagePosition imageRatio : (CGFloat)ratio imageTitleSpace : (CGFloat)imageTitleSpace forState : (UIControlState)state ;
156+ // 同时为functionButton设置标题和图片
157+ - (void )setFunctionButtonWithItem : (SPPageMenuButtonItem *)item forState : (UIControlState)state ;
168158
169159// 为functionButton配置相关属性,如设置字体、文字颜色等;在此,attributes中,只有NSFontAttributeName、NSForegroundColorAttributeName、NSBackgroundColorAttributeName有效
170160- (void )setFunctionButtonTitleTextAttributes : (nullable NSDictionary *)attributes forState : (UIControlState)state ;
@@ -178,21 +168,40 @@ typedef NS_ENUM(NSInteger, SPItemImagePosition) {
178168 }
179169
180170 3.如果外界设置了SPPageMenu的属性"bridgeScrollView",那么外界就可以不用在scrollViewDidScroll方法中调用这个方法来实现跟踪器时刻跟随外界scrollView的效果,内部会自动处理; 外界对SPPageMenu的属性"bridgeScrollView"赋值是实现此效果的最简便的操作
181- 4.如果不想要此效果,可设置closeTrackerFollowingMode==YES
182171 */
183172- (void )moveTrackerFollowScrollView : (UIScrollView *)scrollView ;
184173
185174
186175
187- // -------------- 以下方法和属性被废弃 --------------
176+ // -------------- 以下方法和属性被废弃,不再建议使用 --------------
188177
189178// 设置指定item的四周内边距,3.0版本的时候不小心多写了一个for,3.4.0版本已纠正
190179- (void )setContentEdgeInsets : (UIEdgeInsets)contentEdgeInsets forForItemAtIndex : (NSUInteger )itemIndex NS_DEPRECATED_IOS(6_0, 6_0, " Use -setContentEdgeInsets:forItemAtIndex:" );
191180// 默认NO;关闭跟踪器的跟随效果,在外界传了scrollView进来或者调用了moveTrackerFollowScrollView的情况下,如果为YES,则当外界滑动scrollView时,跟踪器不会时刻跟随,只有滑动结束才会跟随; 3.4.0版本开始被废弃,但是依然能使用,使用后相当于设置了SPPageMenuTrackerFollowingModeEnd枚举值
192181@property (nonatomic, assign) BOOL closeTrackerFollowingMode NS_DEPRECATED_IOS(6_0, 6_0," Use trackerFollowingMode instead" );
193- // 以下2个方法从3.0版本开始有升级,可以使用但不推荐
194- - (void )setTitle : (nullable NSString *)title image : (nullable UIImage *)image imagePosition : (SPItemImagePosition)imagePosition imageRatio : (CGFloat)ratio forItemIndex : (NSUInteger )itemIndex NS_DEPRECATED_IOS(6_0, 6_0, " Use -setTitle:image:imagePosition:imageRatio:imageTitleSpace:forItemIndex:" );
195- - (void )setFunctionButtonTitle : (nullable NSString *)title image : (nullable UIImage *)image imagePosition : (SPItemImagePosition)imagePosition imageRatio : (CGFloat)ratio forState : (UIControlState)state NS_DEPRECATED_IOS(6_0, 6_0, " Use -setFunctionButtonTitle:image:imagePosition:imageRatio:imageTitleSpace:forState:" );
182+ // 下面的方法均有升级,其中ratio参数已失效
183+ - (void )setTitle : (nullable NSString *)title image : (nullable UIImage *)image imagePosition : (SPItemImagePosition)imagePosition imageRatio : (CGFloat)ratio forItemIndex : (NSUInteger )itemIndex NS_DEPRECATED_IOS(6_0, 6_0, " Use -setItem: forItemIndex:" );
184+ - (void )setTitle : (nullable NSString *)title image : (nullable UIImage *)image imagePosition : (SPItemImagePosition)imagePosition imageRatio : (CGFloat)ratio imageTitleSpace : (CGFloat)imageTitleSpace forItemIndex : (NSUInteger )itemIndex NS_DEPRECATED_IOS(6_0, 6_0, " Use -setItem: forItemIndex:" );
185+ - (void )setFunctionButtonTitle : (nullable NSString *)title image : (nullable UIImage *)image imagePosition : (SPItemImagePosition)imagePosition imageRatio : (CGFloat)ratio forState : (UIControlState)state NS_DEPRECATED_IOS(6_0, 6_0, " Use - setFunctionButtonWithItem:forState:" );
186+ - (void )setFunctionButtonTitle : (nullable NSString *)title image : (nullable UIImage *)image imagePosition : (SPItemImagePosition)imagePosition imageRatio : (CGFloat)ratio imageTitleSpace : (CGFloat)imageTitleSpace forState : (UIControlState)state NS_DEPRECATED_IOS(6_0, 6_0, " Use - setFunctionButtonWithItem:forState:" );
187+ @end
188+
189+
190+ // 这个类相当于模型,主要用于同时为某个按钮设置图片和文字时使用
191+ @interface SPPageMenuButtonItem : NSObject
192+
193+ // 快速创建同时含有标题和图片的item,默认图片在左边,文字在右边
194+ + (instancetype )itemWithTitle : (NSString *)title image : (UIImage *)image ;
195+ // 快速创建同时含有标题和图片的item,imagePositiona参数为图片位置
196+ + (instancetype )itemWithTitle : (NSString *)title image : (UIImage *)image imagePosition : (SPItemImagePosition)imagePosition ;
197+
198+ @property (nonatomic , copy ) NSString *title;
199+ @property (nonatomic , strong ) UIImage *image;
200+ // 图片的位置
201+ @property (nonatomic , assign ) SPItemImagePosition imagePosition;
202+ // 图片与标题之间的间距,默认0.0
203+ @property (nonatomic , assign ) CGFloat imageTitleSpace;
204+
196205@end
197206
198207NS_ASSUME_NONNULL_END
0 commit comments