ShareSDK自定义UI的方法

说明:我们的分享菜单可以修改背景,里面的图标以及文字,颜色等,另外可以自己自定义UI,用自己的方法写界面,写好了之后可以调用我们以下无UI的分享方法,另外我们的UI也是开源的。

一、无 UI 分享

#import <ShareSDK/ShareSDK.h> 
//创建分享参数
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:@"分享内容"
                                         images:images //传入要分享的图片
                                            url:[NSURL URLWithString:@"http://mob.com"]
                                          title:@"分享标题"
                                           type:SSDKContentTypeAuto];
 
    //进行分享
    [ShareSDK share:SSDKPlatformTypeSinaWeibo //传入分享的平台类型
         parameters:shareParams
    onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) { // 回调处理....}];
    }
复制代码

二、自定义分享菜单栏样式

// 弹出分享菜单需要导入的头文件
#import <ShareSDK/ShareSDK.h> 
#import <ShareSDKUI/ShareSDK+SSUI.h>
// 自定义分享菜单栏需要导入的头文件
#import <ShareSDKUI/SSUIShareActionSheetStyle.h>
#自定义分享编辑界面所需要导入的头文件
#import <ShareSDKUI/SSUIEditorViewStyle.h>
 
    //1、创建分享参数(必要)
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    NSArray* imageArray = @[[UIImage imageNamed:@"图片名.png"]];
   (注意:图片必须要在Xcode左边目录里面,名称必须要传正确,如果要分享网络图片,可以这样传iamge参数 images:@[@"http://mob.com/Assets/images/logo.png?v=20150320"])
    [shareParams SSDKSetupShareParamsByText:@"分享内容"
                                     images:imageArray
                                        url:[NSURL URLWithString:@"http://mob.com"]
                                      title:@"分享标题"
                                       type:SSDKContentTypeAuto];
 
    // 设置分享菜单栏样式(非必要)
    // 设置分享菜单的背景颜色
    [SSUIShareActionSheetStyle setActionSheetBackgroundColor:[UIColor colorWithRed:249/255.0 green:0/255.0 blue:12/255.0 alpha:0.5]];
    // 设置分享菜单颜色
    [SSUIShareActionSheetStyle setActionSheetColor:[UIColor colorWithRed:21.0/255.0 green:21.0/255.0 blue:21.0/255.0 alpha:1.0]];
    // 设置分享菜单-取消按钮背景颜色
    [SSUIShareActionSheetStyle setCancelButtonBackgroundColor:[UIColor colorWithRed:21.0/255.0 green:21.0/255.0 blue:21.0/255.0 alpha:1.0]];
    // 设置分享菜单-取消按钮的文本颜色
    [SSUIShareActionSheetStyle setCancelButtonLabelColor:[UIColor blackColor]];
    // 设置分享菜单-社交平台文本颜色
    [SSUIShareActionSheetStyle setItemNameColor:[UIColor whiteColor]];
    // 设置分享菜单-社交平台文本字体
    [SSUIShareActionSheetStyle setItemNameFont:[UIFont systemFontOfSize:10]];
   //设置分享编辑界面的导航栏颜色
   [SSUIEditorViewStyle setiPhoneNavigationBarBackgroundColor:[UIColor blackColor]];
  //设置编辑界面标题颜色
  [SSUIEditorViewStyle setTitleColor:[UIColor redColor]];
  //设置取消发布标签文本颜色
   [SSUIEditorViewStyle setCancelButtonLabelColor:[UIColor blueColor]];
    [SSUIEditorViewStyle setShareButtonLabelColor:[UIColor blueColor]];
   //设置分享编辑界面状态栏风格
   [SSUIEditorViewStyle setStatusBarStyle:UIStatusBarStyleLightContent];
  //设置简单分享菜单样式
    [SSUIShareActionSheetStyle setShareActionSheetStyle:ShareActionSheetStyleSimple];
    //2、弹出ShareSDK分享菜单
    [ShareSDK showShareActionSheet:view
                             items:nil
                       shareParams:shareParams
               onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) { ...... }
复制代码

三、跳过分享的编辑界面

设置弹出分享菜单,直接点击菜单中的平台分享(跳过分享的编辑界面)。

#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/SSUIShareActionSheetController.h>
//先构造分享参数:
 NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
  [shareParams SSDKSetupShareParamsByText:@"分享内容"
                                         images:@[[UIImage imageNamed:@"shareImg.png"]]
                                            url:[NSURL URLWithString:@"http://mob.com"]
                                          title:@"分享标题"
                                           type:SSDKContentTypeAuto];
  //有的平台要客户端分享需要加此方法,例如微博
  [shareParams SSDKEnableUseClientShare];
  //调用分享的方法
 SSUIShareActionSheetController *sheet = [ShareSDK showShareActionSheet:view
                                                                         items:nil
                                                                   shareParams:shareParams
                                                           onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
                                                               switch (state) {
                                                                   case SSDKResponseStateSuccess:
                                                                       NSLog(@"分享成功!");
                                                                       break;
                                                                   case SSDKResponseStateFail:
                                                                       NSLog(@"分享失败%@",error);
                                                                       break;
                                                                   case SSDKResponseStateCancel:
                                                                       NSLog(@"分享已取消");
                                                                       break;
                                                                   default:
                                                                       break;
                                                               }
                                                           }];
   //删除和添加平台示例
 [sheet.directSharePlatforms removeObject:@(SSDKPlatformTypeWechat)];(默认微信,QQ,QQ空间都是直接跳客户端分享,加了这个方法之后,可以跳分享编辑界面分享)
 [sheet.directSharePlatforms addObject:@(SSDKPlatformTypeSinaWeibo)];(加了这个方法之后可以不跳分享编辑界面,直接点击分享菜单里的选项,直接分享)
复制代码

四、隐藏“微信收藏”平台

  [ShareSDK registerActivePlatforms:@[
                            // 不要使用微信总平台进行初始化
                            //@(SSDKPlatformTypeWechat),
                            // 使用微信子平台进行初始化,即可
                            @(SSDKPlatformSubTypeWechatSession),
                            @(SSDKPlatformSubTypeWechatTimeline)
                            ]
           onImport:^(SSDKPlatformType platformType)
           {
               switch (platformType)
                  {
                         case SSDKPlatformTypeWechat:
                             [ShareSDKConnector connectWeChat:[WXApi class]];
                             break;
                        default:
                             break;
                     }
 
                 }
          onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
          {
              switch (platformType)
              {
                   case SSDKPlatformTypeWechat:
                      [appInfo SSDKSetupWeChatByAppId:@"wx4868b35061f87885"
                                            appSecret:@"64020361b8ec4c99936c0e3999a9f249"];
                      break;
                   default:
                      break;
              }
          }];
复制代码

五、(分享菜单)平台顺序自定义

ShareSDK提供的UI (分享菜单) 平台顺序自定义。

    //分享
    [ShareSDK showShareActionSheet:nil
                       //将要自定义顺序的平台传入items参数中
                       items:@[@(SSDKPlatformTypeMail),
                               @(SSDKPlatformTypeSMS),
                               @(SSDKPlatformTypeCopy),
                               @(SSDKPlatformTypeFacebook),
                               @(SSDKPlatformTypeTwitter),
                               @(SSDKPlatformTypeWechat),
                               @(SSDKPlatformTypeQQ)]
                       shareParams:shareParams
               onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) { .......}];
复制代码

六、自定义分享菜单项

如果想在我们的分享菜单上添加一个自己的按钮,处理自己想要做的事件,如下所示:

#import <ShareSDKUI/SSUIShareActionSheetCustomItem.h>
//添加一个自定义的平台(非必要)
    SSUIShareActionSheetCustomItem *item = [SSUIShareActionSheetCustomItem itemWithIcon:[UIImage imageNamed:@"Icon.png"]
                                                                                  label:@"自定义"
                                                                                onClick:^{
 
                                                                                    //自定义item被点击的处理逻辑
                                                                                    NSLog(@"=== 自定义item被点击 ===");
                                                                                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"自定义item被点击"
                                                                                                                                        message:nil
                                                                                                                                       delegate:nil
                                                                                                                              cancelButtonTitle:@"确定"
                                                                                                                              otherButtonTitles:nil];
                                                                                    [alertView show];
                                                                                }];
  NSArray * platforms =@[@(SSDKPlatformSubTypeQQFriend),@(SSDKPlatformSubTypeWechatSession),@(SSDKPlatformTypeTencentWeibo),item];
//再把声明的platforms对象传进分享方法里的items参数里
 [ShareSDK showShareActionSheet:nil
                             items:platforms
                       shareParams:shareParams
               onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {}
复制代码







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值