sharesdk自定义UI

//sharesdk idk

//腾讯idk

#import TencentOpenAPI/TencentOAuth.h

#import TencentOpenAPI/QQApiInterface.h

#import "WXApi.h"

#import "WeiboSDK.h"

#import "ShareButton.h"

@interface ShareModel : NSObject

@property (nonatomic ,strong) NSString    *picUrl;

@property (nonatomic ,strong) NSString    *title;

@property (nonatomic ,strong) NSString    *content;

@property (nonatomic ,strong) NSString    *link;

@end

@interface YZShare : NSObject

//注册分享组件

+(void)registApp;

@end

//分享界面

typedef void(^SelectShareTypeBlock)(SSDKPlatformType platfromType ,NSInteger name);

@interface YZShareView :       UIView

@property (nonatomic ,retain)  UIVisualEffectView *blurView;

@property (nonatomic ,copy)    SelectShareTypeBlock selectTypeBlock;

@property (nonatomic ,strong)  UIView *whiteView;

@end

//阴影界面

@interface ShareViewbg : UIView

- (instancetype)initWithFrame:(CGRect)frame shareModel:(ShareModel *)shareModel;

@property (nonatomic ,copy) void(^SSDKResponseStateSuccess)(NSUInteger indexId);

@property (nonatomic ,copy) void(^SSDKResponseStateFail)(NSString *error);

@property (nonatomic ,copy) void(^SSDKResponseStateCancel)();

@property (nonatomic ,copy) void(^dimissShareView)();

@property (nonatomic ,strong) YZShareView *shareView;

@property (nonatomic ,strong) UIView      *bgView;

@end

#import "YZShare.h"

#import "MyConst.h" //导入宏

@interface YZShareView ()

@end

@implementation YZShare

/**

*初始化应用

*/

+ (void)registApp{

[ShareSDK registerApp:@"*********" activePlatforms:@[@(SSDKPlatformSubTypeWechatTimeline),

@(SSDKPlatformSubTypeWechatSession),

@(SSDKPlatformTypeSinaWeibo),

@(SSDKPlatformSubTypeQQFriend),

@(SSDKPlatformSubTypeQZone),

@(SSDKPlatformTypeCopy)

]

onImport:^(SSDKPlatformType platformType) {

switch (platformType) {

case SSDKPlatformTypeWechat:

[ShareSDKConnector connectWeChat:[WXApi class]];

break;

case SSDKPlatformTypeQQ:

[ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];

break;

case SSDKPlatformTypeSinaWeibo:

[ShareSDKConnector connectWeibo:[WeiboSDK class]];

break;

case SSDKPlatformTypeCopy:

{

}

break;

case SSDKPlatformSubTypeQQFriend:

{

}

break;

case SSDKPlatformSubTypeQZone:

{

[ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];

}

break;

default:

break;

}

} onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo) {

switch (platformType) {

case SSDKPlatformTypeSinaWeibo:

[appInfo SSDKSetupSinaWeiboByAppKey:@"********"

appSecret:@"****************"

redirectUri:@"https:********"

authType:SSDKAuthTypeBoth];

break;

case SSDKPlatformTypeWechat:

case SSDKPlatformSubTypeWechatSession:

case SSDKPlatformSubTypeWechatTimeline:

case SSDKPlatformSubTypeWechatFav:

[appInfo SSDKSetupWeChatByAppId:@"********"

appSecret:@"********"];

break;

case SSDKPlatformSubTypeQQFriend:

case SSDKPlatformTypeQQ:

case SSDKPlatformSubTypeQZone:

[appInfo SSDKSetupQQByAppId:@"********"

appKey:@"A********"

authType:SSDKAuthTypeBoth];

break;

default:

break;

}

}];

}

@end

#pragma mark -分享界面

@implementation YZShareView

- (instancetype)initWithFrame:(CGRect)frame{

self =[super initWithFrame:frame];

if (self) {

NSArray *btnTitle=[[NSArray alloc]initWithObjects:@"微信朋友圈",@"微信好友",@"微博",@"QQ好友",@"QQ空间",@"复制链接", nil];

NSArray *images  =[[NSArray alloc]initWithObjects:@"shareWechatZone",@"shareWechant",@"shareWeibo",@"QQ",@"QQZone",@"copy", nil];

int totallo = 3;

CGFloat interval = (self.frame.size.width -totallo *80)/(totallo +1);

for (int i=0; i<5; i++) {

int row = i/totallo;

int loc =i%totallo;

CGFloat x = interval +(interval +80)*loc;

CGFloat y = (self.frame.size.height-80*2-45)/2+135*row;

ShareButton *button = [ShareButton buttonWithType:UIButtonTypeCustom];

button.titleLabel.textAlignment = NSTextAlignmentCenter;

button.tag=220+i;

[button setTitle:btnTitle[i] forState:UIControlStateNormal];

[button setImage:[UIImage imageNamed:images[i]] forState:UIControlStateNormal];

button.titleLabel.font = [UIFont systemFontOfSize:12];

[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

button.frame = CGRectMake(x, y, 80, 80);

button.backgroundColor = [UIColor clearColor];

[self addSubview:button];

[button addTarget:self action:@selector(shareClick:) forControlEvents:UIControlEventTouchUpInside];

#pragma mark- 根据验证该平台是否可以分享,来确定按钮的点击事件是否可以点击

switch (i) {

case 0:

{

button.enabled=[ShareSDK isClientInstalled:SSDKPlatformTypeWechat];

if (button.enabled==NO) {

button.hidden=YES;

}

break;

}

case 1:

{

button.enabled=[ShareSDK isClientInstalled:SSDKPlatformSubTypeWechatSession];

if (button.enabled==NO) {

button.hidden=YES;

}

break;

}

case 2:

{

[ShareSDK isClientInstalled:SSDKPlatformTypeSinaWeibo];

//                    button.enabled=[ShareSDK isClientInstalled:SSDKPlatformTypeSinaWeibo];

//                    if (button.enabled==NO) {

//                        button.hidden=YES;

//                    }

}

break;

case 3:

{

button.enabled =[ShareSDK isClientInstalled:SSDKPlatformSubTypeQQFriend];

if (button.enabled==NO) {

button.hidden=YES;

}

break;

}

case 4:

{

button.enabled =[ShareSDK isClientInstalled:SSDKPlatformSubTypeQZone];

if (button.enabled ==NO) {

button.hidden =YES;

}

break;

}

case 5:

#pragma mark 复制链接

NSLog(@"----");

break;

default:

break;

}

}

}

return self;

}

#pragma mark -分享点击事件

- (void)shareClick:(ShareButton *)btn{

switch (btn.tag) {

case 220:

_selectTypeBlock(SSDKPlatformSubTypeWechatTimeline,1);

break;

case 221:

_selectTypeBlock(SSDKPlatformSubTypeWechatSession,2);

break;

case 222:

_selectTypeBlock(SSDKPlatformTypeSinaWeibo,3);

break;

case 223:

_selectTypeBlock(SSDKPlatformSubTypeQQFriend,4);

break;

case 224:

_selectTypeBlock(SSDKPlatformSubTypeQZone,5);

break;

case 225:

NSLog(@"复制链接");

break;

default:

break;

}

}

@end

#pragma mark -阴影view

@implementation ShareViewbg

- (instancetype)initWithFrame:(CGRect)frame shareModel:(ShareModel *)shareModel{

if (self =[super initWithFrame:frame]) {

self.bgView =[[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];

self.bgView.backgroundColor =[UIColor blackColor];

self.bgView.alpha=0.6;

[[UIApplication sharedApplication].keyWindow addSubview:self.bgView];

UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dimissShareView:)];

[self.bgView addGestureRecognizer:tap];

if (shareModel==nil) {

ShareModel *model=[ShareModel new];

shareModel =model;

model.picUrl=@"http://www.eurlion.com";

model.title =@"理安保险";

model.content=@"理安保险测试内容....";

model.link=@"asdsadsa";

}

NSData *imageData =[NSData dataWithContentsOfURL:[NSURL URLWithString:shareModel.picUrl]];

NSMutableDictionary *shareParams =[NSMutableDictionary dictionary];

//设置分享的参数...

[shareParams SSDKSetupShareParamsByText:shareModel.content images:[UIImage imageWithData:imageData] url:[NSURL URLWithString:shareModel.picUrl] title:shareModel.title type:SSDKContentTypeAuto];

[self selectShareWithType:^(SSDKPlatformType platformType) {

[ShareSDK share:platformType parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {

switch (state) {

case SSDKResponseStateBegin:

{

//开始

}

break;

case SSDKResponseStateSuccess:

{

//分享成功,分享界面消失

self.SSDKResponseStateSuccess(platformType);

[self dimissShareView:nil];

}

break;

case SSDKResponseStateFail:

{

//分享失败

self.SSDKResponseStateFail([NSString stringWithFormat:@"%@",error]);

}

break;

case SSDKResponseStateCancel:

{

//分享取消,分享界面消失..

self.SSDKResponseStateCancel();

[self dimissShareView:nil];

}

break;

default:

break;

}

if (state !=SSDKResponseStateBegin) {

//加载结束

}

}];

}];

}

return self;

}

#pragma mark -显示分享选项

- (void)selectShareWithType:(void(^)(SSDKPlatformType platformType))SelectedPlatformType{

self.shareView =[[YZShareView alloc]initWithFrame:CGRectMake(screenWidth/2-(screenWidth-40)/2, screenHeigh/2-(screenWidth-40)/2, screenWidth-40, screenWidth-40)];

self.shareView.backgroundColor =[UIColor whiteColor];

self.shareView.clipsToBounds=YES;

self.shareView.layer.cornerRadius=10;

[[UIApplication sharedApplication].keyWindow addSubview:self.shareView];

self.shareView.selectTypeBlock=^(SSDKPlatformType platfromType ,NSInteger nameId){

SelectedPlatformType(platfromType);

};

}

#pragma mark -消失

- (void)dimissShareView:(id)sender{

[self.bgView removeFromSuperview];

[self.shareView removeFromSuperview];

[self removeFromSuperview];

}

@end

#pragma mark -分享数据的模型

@implementation ShareModel

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,454评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,553评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,921评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,648评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,770评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,950评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,090评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,817评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,275评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,592评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,724评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,409评论 4 333
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,052评论 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,815评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,043评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,503评论 2 361
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,627评论 2 350

推荐阅读更多精彩内容