ShareSDK自定义UI的方法

ShareSDK自定义UI的方法

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

一、无 UI 分享

#import

//创建分享参数

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

#import

// 自定义分享菜单栏需要导入的头文件

#import

#自定义分享编辑界面所需要导入的头文件

#import

//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

#import

//先构造分享参数:

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

//添加一个自定义的平台(非必要)

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) {}


分享到:


相關文章: