项目作者: liugangios

项目描述 :
IFMShare是一个iOS客户端应用内分享的界面、功能一体化解决方案,使用简单、优雅,界面和功能高度可定制化。分享功能直接调用iOS系统内预制分享功能,无需去各种繁杂的社会化分享平台注册账号、无需下载导入各种SDK,使用非常简单。
高级语言: Objective-C
项目地址: git://github.com/liugangios/IFMShare.git
创建时间: 2017-08-14T03:16:25Z
项目社区:https://github.com/liugangios/IFMShare

开源协议:MIT License

关键词:
"ifmshare" "ios-share" "share"

下载


IFMShare

IFMShare(Swift版)是一个iOS客户端应用内分享的界面、功能一体化解决方案,使用简单、优雅,界面和功能高度可定制化。分享功能直接调用iOS系统内预制分享功能,无需去各种繁杂的社会化分享平台注册账号、无需下载导入各种SDK,使用非常简单。

Demo展示

图片展示

图片展示

GIF展示

动图展示

使用

在项目中导入IFMShareView.h,执行以下代码即可

  1. IFMShareView *shareView = [[IFMShareView alloc] initWithItems:@[IFMPlatformNameSms,IFMPlatformNameEmail,IFMPlatformNameQQ,IFMPlatformNameWechat] itemSize:CGSizeMake(80,100) DisplayLine:YES];
  2. //设置分享内容
  3. [shareView addText:@"分享测试"];
  4. [shareView addURL:[NSURL URLWithString:@"http://www.baidu.com"]];
  5. [shareView addImage:image];
  6. [shareView showFromControlle:self];

介绍

IFMShare由三个类组成,IFMShareView、IFMShareItemIFMShareItemCell。其中IFMShareItemCellUICollectionView的单元格,用户可以忽略它,

IFMShareItem

IFMShareItem是每一个要展示的cell的数据源,它有三种初始化方法,

  1. - (instancetype)initWithImage:(UIImage *)image
  2. title:(NSString *)title
  3. action:(shareHandle)action;
  4. - (instancetype)initWithImage:(UIImage *)image
  5. title:(NSString *)title
  6. actionName:(NSString *)actionName;
  7. - (instancetype)initWithPlatformName:(NSString *)platformName;

- (instancetype)initWithPlatformName:(NSString *)platformName;只需要传入预制的分享平台名称,比如:

  1. IFMPlatformNameSina; // 新浪微博
  2. IFMPlatformNameQQ; //QQ
  3. IFMPlatformNameEmail; //邮箱
  4. IFMPlatformNameSms; //短信

即可快速初始化一个包括title、image和action的分享cell

如果提供的image不符合您的要求,您可以使用以下方法初始化一个IFMShareItem

  1. - (instancetype)initWithImage:(UIImage *)image
  2. title:(NSString *)title
  3. actionName:(NSString *)actionName;

其中actionName传入预制的分享action,比如:

  1. IFMPlatformHandleSina; // 新浪微博
  2. IFMPlatformHandleQQ; //QQ
  3. IFMPlatformHandleEmail; //邮箱
  4. IFMPlatformHandleSms; //短信

如果预制的action不能满足您的分享内容类型,还可以使用以下方法,

  1. - (instancetype)initWithImage:(UIImage *)image
  2. title:(NSString *)title
  3. action:(shareHandle)action;

action是一个Block块,类型如下,

  1. typedef void (^__nullable shareHandle)(IFMShareItem *item);

您可以在这个Block块里写入点击按钮以后需要执行的动作。

IFMShareView

IFMShareView是包含了所有展示控件的View,提供了三种初始化方法

  1. - (instancetype)initWithItems:(NSArray *)items itemSize:(CGSize)itemSize DisplayLine:(BOOL)inLine;
  2. - (instancetype)initWithShareItems:(NSArray *)shareItems functionItems:(NSArray *)functionItems itemSize:(CGSize)itemSize;
  3. - (instancetype)initWithItems:(NSArray *)items countEveryRow:(NSInteger)count;//默认九宫格样式

如果您要展示的是一个单行的分享界面,使用以下方法:

  1. - (instancetype)initWithItems:(NSArray *)items itemSize:(CGSize)itemSize DisplayLine:(BOOL)inLine;

如果是双行,您一定猜到了,使用以下方法:

  1. - (instancetype)initWithShareItems:(NSArray *)shareItems functionItems:(NSArray *)functionItems itemSize:(CGSize)itemSize;

其中itemSize是需要传入的IFMShareItemCell大小,IFMShareView会根据传入的itemSize自动调整自己的大小。如果您想使用默认大小,传入一个预制的宏IFMShareItemCellSize,为CGSizeMake(80, 100)shareItems是第一行的分享性质的按钮数组,functionItems是第二行功能性质的按钮数组,存放的是IFMShareItem或者预制的分享平台名称,比如:IFMPlatformNameSina、IFMPlatformNameEmail

如果您要使用的分享界面是一个九宫格类型的,使用以下初始化方法

  1. - (instancetype)initWithItems:(NSArray *)items countEveryRow:(NSInteger)count;//默认九宫格样式

count表示每一行展示的item个数,

个性化

除了以上功能,IFMShare还提供了丰富的可定制属性。

  1. @property (nullable, nonatomic, strong) UIView *headerView;//头部分享标题
  2. @property (nullable, nonatomic, strong) UIView *footerView;//尾部其他自定义View

可以传入用户绘制好的头部和尾部的View,IFMShareView会将它们放在合适的位置。

  1. @property (nonatomic, strong) UIButton *cancleButton;//取消

用户可以获取到底部取消按钮,修改它的背景色、标题、圆角等。

  1. @property (nullable, nonatomic, strong) UIColor *middleLineColor;//分割线颜色
  2. @property (nonatomic) CGFloat middleLineEdgeSpace;//分割线边距
  3. @property (nonatomic) CGFloat middleTopSpace;//分割线距离上部按钮距离
  4. @property (nonatomic) CGFloat middleBottomSpace;//分割线距离下部按钮距离

可以设置分割线的各种属性,以及以下属性:

  1. @property (nullable, nonatomic, strong) UIColor *containViewColor;
  2. @property (nullable, nonatomic, strong) UIFont *itemTitleFont; //标题字体大小
  3. @property (nullable, nonatomic, strong) UIColor *itemTitleColor; //标题字体颜色
  4. @property (nonatomic) UIEdgeInsets bodyViewEdgeInsets;//中间bodyView的边距;
  5. @property (nonatomic) CGSize itemSize; //item大小
  6. @property (nonatomic) CGSize itemImageSize; //item中image大小
  7. @property (nonatomic) BOOL showBorderLine; //是否显示cell边界线
  8. @property (nonatomic) CGFloat itemImageTopSpace; //item图片距离顶部大小
  9. @property (nonatomic) CGFloat iconAndTitleSpace; //item图片和文字距离
  10. @property (nonatomic) CGFloat itemSpace;//item横向间距
  11. @property (nonatomic) BOOL showsHorizontalScrollIndicator;//是否显示横向滚动条
  12. @property (nonatomic) BOOL showCancleButton;//是否显示取消按钮

您可以试着玩一玩。使用过程中有任何问题,请在issue中提出,或者邮件联系我,或者关注我的新浪微博@小刘大刚,我会及时修改更新,谢谢您的支持,希望我的代码可以给您灵感,同时也帮助我成长,世界因为开源而美好。

TODO

  • 支持cocoapods
  • 加入更多预制平台
  • 介绍对比4种分享方案