CNLiveThreeLoginView.m
5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// CNLiveThreeLoginView.m
// CNLiveLoginModule
//
// Created by CNLive-zxw on 2019/9/6.
// Copyright © 2019 153993236@qq.com. All rights reserved.
//
#import "CNLiveThreeLoginView.h"
#import "YYKit.h"
#import "CNLiveCategory.h"
#import "CNLiveShareImageManager.h"
#import "WXApi.h"
#import <AuthenticationServices/AuthenticationServices.h>
@interface CNLiveThreeLoginView()
@end
@implementation CNLiveThreeLoginView
static NSInteger const rowHeight = 60;
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
[self createSubviews:frame];
}
return self;
}
- (void)createSubviews:(CGRect)frame{
CGFloat width = frame.size.width;
CGFloat nameWidth = width/3.0;
CGFloat lineLeft = 15;
CGFloat lineWidth = nameWidth - lineLeft*2;
UIView *leftLine = [[UIView alloc] initWithFrame:CGRectMake(lineLeft, (rowHeight/3.0-1)/2.0, lineWidth, 1)];
leftLine.backgroundColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0];
[self addSubview:leftLine];
UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(nameWidth, 0, nameWidth, rowHeight/3.0)];
name.textColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0];
name.font = [UIFont systemFontOfSize:14];
name.textAlignment = NSTextAlignmentCenter;
name.text = @"第三方账号登录";
[self addSubview:name];
UILabel *rightLine = [[UILabel alloc] initWithFrame:CGRectMake(name.right+15, leftLine.top, leftLine.width, 1)];
rightLine.backgroundColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0];
[self addSubview:rightLine];
NSMutableArray *pics = [NSMutableArray arrayWithArray:@[@"login_qq",@"login_weibo"]];
if([WXApi isWXAppInstalled]||[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"wechat://"]]){
[pics insertObject:@"login_wechat" atIndex:0];
}
NSUInteger number = pics.count;
if (@available(iOS 13, *)) {
[pics addObject:@"login_apple"];
number = pics.count + 1;
}
CGFloat btnWidth = width/number*1.0;
for(int i = 0; i < pics.count; i++){
// 苹果登录在最后一个
if (pics.count-1 == i && [pics[pics.count-1] isEqualToString:@"login_apple"]) {
if (@available(iOS 13, *)) {
ASAuthorizationAppleIDButton *btn = [ASAuthorizationAppleIDButton buttonWithType:ASAuthorizationAppleIDButtonTypeDefault style:ASAuthorizationAppleIDButtonStyleWhite];
btn.tag = 10000+i;
btn.layer.masksToBounds = YES;
btn.layer.cornerRadius = 18.0;
btn.layer.borderWidth = 1.0;
btn.layer.borderColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0].CGColor;
btn.frame = CGRectMake(btnWidth*i, name.bottom+12, 2*btnWidth, 36);
[btn addTarget:self action:@selector(btnDidClicked:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:btn];
}
}else {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.tag = 10000+i;
btn.frame = CGRectMake(btnWidth*i, name.bottom, btnWidth, rowHeight);
UIImage *image = [self getImageWithImageName:pics[i] bundleName:@"CNLiveBLoginModule" targetClass:[self class]];
[btn setImage:image forState:UIControlStateNormal];
btn.adjustsImageWhenHighlighted = NO;
[btn addTarget:self action:@selector(btnDidClicked:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:btn];
}
}
}
- (void)btnDidClicked:(UIButton *)btn{
if([WXApi isWXAppInstalled]||[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"wechat://"]]){
if (self.delegate && [self.delegate respondsToSelector:@selector(clickedButton:type:)]) {
if(btn.tag == 10000){
[self.delegate clickedButton:self type:CNLiveSendAuthRespWX];
}else if (btn.tag == 10001){
[self.delegate clickedButton:self type:CNLiveSendAuthRespQQ];
}else if(btn.tag == 10002){
[self.delegate clickedButton:self type:CNLiveSendAuthRespWB];
}else if(btn.tag == 10003){
[self.delegate clickedButton:self type:CNLiveSendAuthRespApple];
}
}
}else{
if (self.delegate && [self.delegate respondsToSelector:@selector(clickedButton:type:)]) {
if(btn.tag == 10000){
[self.delegate clickedButton:self type:CNLiveSendAuthRespQQ];
}else if(btn.tag == 10001){
[self.delegate clickedButton:self type:CNLiveSendAuthRespWB];
}else if(btn.tag == 10002){
[self.delegate clickedButton:self type:CNLiveSendAuthRespApple];
}
}
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end