NSArray *imageArray=[[NSArray alloc]initWithObjects:@"btn_3_weixin",@"btn_3_qq",@"btn_3_weibo", nil];
UIImageView *shareButton;
CGFloat firstButtonWdith=0;
CGFloat axisY=functionButton.frame.origin.y+functionButton.frame.size.height+40;
CGFloat thisWidht=DEVICE_Width-76;
UILabel *thisShareLabel;
for (int sh=0;sh<3;sh++) {
shareButton=[[UIImageView alloc]init];
if (sh==0) {
thisShareLabel=[[UILabel alloc]initWithFrame:CGRectMake(38, axisY+7, thisWidht*0.25, 1)];
thisShareLabel.backgroundColor=[UIColor whiteColor];
shareButton.frame = CGRectMake( thisShareLabel.frame.origin.x+thisShareLabel.frame.size.width*0.18 , thisShareLabel.frame.origin.y+20,thisShareLabel.frame.size.width*0.64 , thisShareLabel.frame.size.width*0.64);
firstButtonWdith=shareButton.frame.size.width;
}
else if(sh==1)
{
thisShareLabel=[[UILabel alloc]initWithFrame:CGRectMake(thisShareLabel.frame.size.width+thisShareLabel.frame.origin.x, axisY, thisWidht*0.5, 14)];
thisShareLabel.text=@"第三方账户登录";
shareButton.frame = CGRectMake( thisShareLabel.frame.origin.x+thisShareLabel.frame.size.width/2-(firstButtonWdith/2) , thisShareLabel.frame.origin.y+26,firstButtonWdith, firstButtonWdith);
}
else
{
thisShareLabel=[[UILabel alloc]initWithFrame:CGRectMake(thisShareLabel.frame.size.width+thisShareLabel.frame.origin.x, axisY+7, thisWidht*0.25, 1)];
thisShareLabel.backgroundColor=[UIColor whiteColor];
shareButton.frame = CGRectMake( thisShareLabel.frame.origin.x+thisShareLabel.frame.size.width*0.18 , thisShareLabel.frame.origin.y+20,thisShareLabel.frame.size.width*0.64 , thisShareLabel.frame.size.width*0.64);
}
thisShareLabel.font=[UIFont systemFontOfSize:14];
thisShareLabel.textAlignment=NSTextAlignmentCenter;
thisShareLabel.textColor=[UIColor whiteColor];
[self addSubview:thisShareLabel];
[shareButton setImage:[UIImage imageNamed:[imageArray objectAtIndex:sh]]];
shareButton.userInteractionEnabled=YES;
UIGestureRecognizer *thirdSDKLoginUIGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(thirdSDKLogin:)];
[shareButton addGestureRecognizer:thirdSDKLoginUIGestureRecognizer];
shareButton.tag=123456+sh;
[self addSubview:shareButton];
if (sh==2) {
self.backScrollView .scrollEnabled=YES;
if (DEVICE_Height<500) {
[self.backScrollView setContentSize:CGSizeMake(DEVICE_Width, self.backScrollView.contentSize.height+50)];
}
}
}
这里首先需要实现功能的ViewController中引入对应的库
#import "UMSocial.h"
#import "WXApi.h"
#import <TencentOpenApi/QQApiInterface.h>
#import "WeiboSDK.h"
下面的方法就是就是上面代码中UIImageView *shareButton绑定的手势,这里为什么要使用UIImageView,
因为我代码布局中 shareButton的宽度和高度没有固定,是根据屏幕的宽度来计算的,如果使用UIButton就会出现
贴的图片的大小不会随着动态计算出的高宽而缩放,如果写代码放大缩小又会出现模糊状态。
//公用的跳转用户资料详情页面
-(void)thirdSDKLogin:(UITapGestureRecognizer *)sender
{
UIImageView *view=(UIImageView *)sender.self.view;
if (view.tag==123456 ) {
//判断微信客户端是否安装
if ([WXApi isWXAppInstalled]) {
NSString *platformName = [UMSocialSnsPlatformManager getSnsPlatformString:UMSocialSnsTypeWechatSession];
UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession];
snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
NSLog(@"login response is %@",response);
//获取微博用户名、uid、token等
if (response.responseCode == UMSResponseCodeSuccess) {
UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:platformName];
NSLog(@"username is %@, uid is %@, token is %@,iconUrl is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
}
});
}
else
{
showMessage(@"请先安装微信客户端。");
return;
}
}
else if(view.tag==123457)
{
//判断qq客户端是否安装
if ([QQApiInterface isQQInstalled]) {
NSString *platformName = [UMSocialSnsPlatformManager getSnsPlatformString:UMSocialSnsTypeMobileQQ];
UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ];
snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
NSLog(@"login response is %@",response);
//获取微博用户名、uid、token等
if (response.responseCode == UMSResponseCodeSuccess) {
UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:platformName];
NSLog(@"username is %@, uid is %@, token is %@,iconUrl is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
}
});
}
else{
showMessage(@"请先安装qq客户端。");
return;
}
}
else
{
//判断sina客户端是否安装
if ([WeiboSDK isCanShareInWeiboAPP])
{
/*新浪登录第三方登录授权*/
NSString *platformName = [UMSocialSnsPlatformManager getSnsPlatformString:UMSocialSnsTypeSina];
UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
NSLog(@"response is %@",response);
if (response.responseCode == UMSResponseCodeSuccess) {
UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:platformName];
NSLog(@"=========%@",snsAccount.accessToken);
}
});
}
else
{
showMessage(@"请先安装新浪微博客户端。");
return;
}
}
}