GithubHelp home page GithubHelp logo

evilino / sppagemenu Goto Github PK

View Code? Open in Web Editor NEW

This project forked from spstore/sppagemenu

0.0 2.0 0.0 3.51 MB

分页菜单,功能非常齐全,满足绝大多数APP,简书地址:

Home Page: http://www.jianshu.com/p/d746b550b541

Objective-C 96.50% Ruby 3.50%

sppagemenu's Introduction

SPPageMenu

Build Status Pod Version Pod Platform Pod License Carthage compatible codecov

安装

版本2.5.3

target 'MyApp' do
  pod 'SPPageMenu', '~> 2.5.3'
end

版本2.5.5

target 'MyApp' do
  pod 'SPPageMenu', '~> 2.5.5'
end

终端输入命令:pod install

说明:2.5.5版本在2.5.3版本的基础上改动如下:

1、增加可以设置跟踪器宽度的属性,增加可以设置跟踪器高度和圆角半径的方法
2、修复了当未选中按钮颜色的alpha值小于1时,颜色渐变不准确问题
3、废弃了文字缩放(SPPageMenuTrackerStyleTextZoom)的枚举,该枚举由属性selectedItemZoomScale 代替,增加了SPPageMenuTrackerStyleNothing枚举
4、可以设置分割线高度

部分功能演示图

(友情提示:如果您的网络较慢,gif图可能会延迟加载,您可以先把宝贵的时间浏览其它信息)

image

所有方法和属性

// 创建pagMenu
+ (instancetype)pageMenuWithFrame:(CGRect)frame trackerStyle:(SPPageMenuTrackerStyle)trackerStyle;
- (instancetype)initWithFrame:(CGRect)frame trackerStyle:(SPPageMenuTrackerStyle)trackerStyle;
/**
 *  传递数组(数组元素只能是NSString或UIImage类型)
 *
 *  @param items    数组
 *  @param selectedItemIndex  选中哪个item
 */
- (void)setItems:(nullable NSArray *)items selectedItemIndex:(NSUInteger)selectedItemIndex;
/** 选中的item下标 */
@property (nonatomic) NSUInteger selectedItemIndex;
/** 外界的srollView,pageMenu会监听该scrollView的滚动状况,让跟踪器时刻跟随此scrollView滑动 */
@property (nonatomic, strong) UIScrollView *bridgeScrollView;
/** 关闭跟踪器的跟随效果,在外界传了scrollView进来或者调用了moveTrackerFollowScrollView的情况下,如果为YES,则当外界滑动scrollView时,跟踪器不会时刻跟随,只有滑动结束才会跟踪; 如果为NO,跟踪器会时刻跟随scrollView */
@property (nonatomic, assign) BOOL closeTrackerFollowingfMode;
/** 是否显示功能按钮(功能按钮显示在最右侧),默认为NO */
@property (nonatomic, assign) BOOL showFuntionButton;
/** item之间的间距,当permutationWay为‘SPPageMenuPermutationWayNotScrollAdaptContent’时此属性无效 */
@property (nonatomic, assign) CGFloat itemPadding;
/** item的标题字体 */
@property (nonnull, nonatomic, strong) UIFont *itemTitleFont;
/** 选中的item标题颜色 */
@property (nonatomic, strong) UIColor *selectedItemTitleColor;
/** 未选中的item标题颜色 */
@property (nonatomic, strong) UIColor *unSelectedItemTitleColor;
/** 跟踪器的宽度 */
@property (nonatomic, assign)  CGFloat trackerWidth;
/** 跟踪器 */
@property (nonatomic, readonly) UIImageView *tracker;
/** 分割线的高度,默认高度为0.5 */
@property (nonatomic) CGFloat dividingLineHeight;
/** 分割线 */
@property (nonatomic, readonly) UIImageView *dividingLine;
/** 代理 */
@property (nonatomic, weak) id<SPPageMenuDeleagte> delegate;
/** 内容的四周内边距(内容不包括分割线) */
@property (nonatomic, assign) UIEdgeInsets contentInset;
/** 排列方式 */
@property (nonatomic, assign) SPPageMenuPermutationWay permutationWay;
// 设置跟踪器的高度和圆角半径,矩形和圆角矩形样式下半径参数无效。其余样式下:默认的高度为3,圆角半径为高度的一半。之所以高度和半径以一个方法而不是2个属性的形式来设置,是因为不想提供太多的属性,其次跟踪器的高度一般用默认高度就好,自定义高度的情况并不会太多。另外,如果你想用默认高度,但是又不想要圆角半径,你可以设置trackerHeight为3,cornerRadius为0,这是去除默认半径的唯一办法
- (void)setTrackerHeight:(CGFloat)trackerHeight cornerRadius:(CGFloat)cornerRadius;
// 插入item,插入和删除操作时,如果itemIndex超过了了items的个数,则不做任何操作
- (void)insertItemWithTitle:(nullable NSString *)title atIndex:(NSUInteger)itemIndex animated:(BOOL)animated;
- (void)insertItemWithImage:(nullable UIImage *)image  atIndex:(NSUInteger)itemIndex animated:(BOOL)animated;
// 如果移除的正是当前选中的item(当前选中的item下标不为0),删除之后,选中的item会切换为上一个item
- (void)removeItemAtIndex:(NSUInteger)itemIndex animated:(BOOL)animated;
- (void)removeAllItems;
// 设置指定item的标题,设置后,如果原先的item为image,则image会被title替换
- (void)setTitle:(nullable NSString *)title forItemAtIndex:(NSUInteger)itemIndex;
// 获取指定item的标题
- (nullable NSString *)titleForItemAtIndex:(NSUInteger)itemIndex;
// 设置指定item的图片,设置后,如果原先的item为title,则title会被图片替换
- (void)setImage:(nullable UIImage *)image forItemAtIndex:(NSUInteger)itemIndex;
// 获取指定item的图片
- (nullable UIImage *)imageForItemAtIndex:(NSUInteger)itemIndex;
// 设置指定item的enabled状态
- (void)setEnabled:(BOOL)enaled forItemAtIndex:(NSUInteger)itemIndex;
// 获取指定item的enabled状态
- (BOOL)enabledForItemAtIndex:(NSUInteger)itemIndex;
// 设置指定item的宽度(如果width为0,则item将自动计算)
- (void)setWidth:(CGFloat)width forItemAtIndex:(NSUInteger)itemIndex;
// 获取指定item的宽度
- (CGFloat)widthForItemAtIndex:(NSUInteger)itemIndex;
/**
 *  同时为指定item设置标题和图片
 *
 *  @param title    标题
 *  @param image    图片
 *  @param imagePosition    图片的位置,分上、左、下、右
 *  @param ratio            图片所占item的比例,默认0.5,如果给0,同样会自动默认为0.5
 *  @param itemIndex        item的下标
 */
- (void)setTitle:(nullable NSString *)title image:(nullable UIImage *)image imagePosition:(SPItemImagePosition)imagePosition imageRatio:(CGFloat)ratio forItemIndex:(NSUInteger)itemIndex;
/**
 *  同时为functionButton设置标题和图片
 *
 *  @param title    标题
 *  @param image    图片
 *  @param imagePosition    图片的位置,分上、左、下、右
 *  @param ratio            图片所占item的比例,默认0.5,如果给0,同样会自动默认为0.5
 *  @param state            控件状态
 */
- (void)setFunctionButtonTitle:(nullable NSString *)title image:(nullable UIImage *)image imagePosition:(SPItemImagePosition)imagePosition imageRatio:(CGFloat)ratio forState:(UIControlState)state;
/* 为functionButton配置相关属性,如设置字体、文字颜色等
   在此,attributes中,只有NSFontAttributeName、NSForegroundColorAttributeName、NSBackgroundColorAttributeName有效
 */
- (void)setFunctionButtonTitleTextAttributes:(nullable NSDictionary *)attributes forState:(UIControlState)state;
/* 1.让跟踪器时刻跟随外界scrollView滑动,实现了让跟踪器的宽度逐渐适应item宽度的功能;如果不想要这个功能
   2.这个方法用于scrollViewDidScroll代理方法中,如
 
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        [self.pageMenu moveTrackerFollowScrollView:scrollView];
    }
 
    3.如果外界对SPPageMenu的属性"bridgeScrollView"赋了值,那么外界就可以不用在scrollViewDidScroll方法中调用这个方法来实现跟踪器时刻跟随外界scrollView的效果,内部会自动处理; 外界对SPPageMenu的属性"bridgeScrollView"赋值是实现此效果的最简便的操作
    4.如果不想要此效果,可设置closeTrackerFollowingfMode==YES
 */
- (void)moveTrackerFollowScrollView:(UIScrollView *)scrollView;
// 代理方法
- (void)pageMenu:(SPPageMenu *)pageMenu functionButtonClicked:(UIButton *)functionButton;
// 若以下2个代理方法同时实现了,那么只会走第2个代理方法
- (void)pageMenu:(SPPageMenu *)pageMenu itemSelectedAtIndex:(NSInteger)index;
- (void)pageMenu:(SPPageMenu *)pageMenu itemSelectedFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex;

使用示例大家可以把demo下载到本地,里面有非常多的示例以及详细的注释

sppagemenu's People

Contributors

spstore avatar

Watchers

veen avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.