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- 根據(jù)驗證該平臺是否可以分享,來確定按鈕的點擊事件是否可以點擊

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];

//設置分享的參數(shù)...

[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 -分享數(shù)據(jù)的模型

@implementation ShareModel

@end

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末恋腕,一起剝皮案震驚了整個濱河市商源,隨后出現(xiàn)的幾起案子出爹,更是在濱河造成了極大的恐慌,老刑警劉巖铸董,帶你破解...
    沈念sama閱讀 217,826評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異卓鹿,居然都是意外死亡,警方通過查閱死者的電腦和手機拔疚,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,968評論 3 395
  • 文/潘曉璐 我一進店門吸占,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人初厚,你說我怎么就攤上這事楞件。” “怎么了障簿?”我有些...
    開封第一講書人閱讀 164,234評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我粱甫,道長,這世上最難降的妖魔是什么裸燎? 我笑而不...
    開封第一講書人閱讀 58,562評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮德绿,結果婚禮上荷荤,老公的妹妹穿的比我還像新娘。我一直安慰自己移稳,他們只是感情好蕴纳,可當我...
    茶點故事閱讀 67,611評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著个粱,像睡著了一般古毛。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上都许,一...
    開封第一講書人閱讀 51,482評論 1 302
  • 那天稻薇,我揣著相機與錄音,去河邊找鬼胶征。 笑死塞椎,一個胖子當著我的面吹牛,可吹牛的內容都是我干的睛低。 我是一名探鬼主播案狠,決...
    沈念sama閱讀 40,271評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼服傍,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了骂铁?” 一聲冷哼從身側響起吹零,我...
    開封第一講書人閱讀 39,166評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎从铲,沒想到半個月后瘪校,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,608評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡名段,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,814評論 3 336
  • 正文 我和宋清朗相戀三年阱扬,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片伸辟。...
    茶點故事閱讀 39,926評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡麻惶,死狀恐怖,靈堂內的尸體忽然破棺而出信夫,到底是詐尸還是另有隱情窃蹋,我是刑警寧澤,帶...
    沈念sama閱讀 35,644評論 5 346
  • 正文 年R本政府宣布静稻,位于F島的核電站警没,受9級特大地震影響,放射性物質發(fā)生泄漏振湾。R本人自食惡果不足惜杀迹,卻給世界環(huán)境...
    茶點故事閱讀 41,249評論 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望押搪。 院中可真熱鬧树酪,春花似錦、人聲如沸大州。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,866評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽厦画。三九已至疮茄,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間根暑,已是汗流浹背娃豹。 一陣腳步聲響...
    開封第一講書人閱讀 32,991評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留购裙,地道東北人。 一個月前我還...
    沈念sama閱讀 48,063評論 3 370
  • 正文 我出身青樓鹃栽,卻偏偏與公主長得像躏率,于是被迫代替她去往敵國和親躯畴。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,871評論 2 354

推薦閱讀更多精彩內容