CNLiveThirdLoginView.m
2.82 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
//
// CNLiveThirdLoginView.m
// CNLiveScioLive
//
// Created by Xiaowen Zhang on 2018/9/19.
// Copyright © 2018年 CNLive. All rights reserved.
//
#import "CNLiveThirdLoginView.h"
#import <AuthenticationServices/AuthenticationServices.h>
@interface CNLiveThirdLoginView()
@property (nonatomic, strong) UILabel *titleLabel;
@end
@implementation CNLiveThirdLoginView
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self setUpUI];
}
return self;
}
-(void)setBtns:(NSArray *)btns{
_btns = btns;
NSInteger count = btns.count;
if (@available(iOS 13, *)) {
count = count + 1;
}
CGFloat width = MainScreenWidth*1.0/count;
for(int i = 0; i < btns.count; i++){
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(i*width, 40, width, 60);
btn.tag = 1000+i;
btn.layer.masksToBounds = YES;
[btn setImage:[[UIImage imageNamed:btns[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(clickedLoginBtn:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:btn];
}
if (@available(iOS 13, *)) {
ASAuthorizationAppleIDButton *btn = [ASAuthorizationAppleIDButton buttonWithType:ASAuthorizationAppleIDButtonTypeDefault style:ASAuthorizationAppleIDButtonStyleBlack];
btn.tag = 1000+(count-1);
btn.layer.masksToBounds = YES;
btn.layer.cornerRadius = 22.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((count-1)*width+20, 48, 44, 44);
[btn addTarget:self action:@selector(clickedLoginBtn:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:btn];
}
}
- (void)setUpUI{
_titleLabel = [[UILabel alloc] init];
_titleLabel.numberOfLines = 1;
_titleLabel.textColor = HEXCOLOR(0x333333);
_titleLabel.font = [UIFont systemFontOfSize:15];
_titleLabel.text = CustomStr(@"ThirdPartyLogin");
_titleLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:_titleLabel];
}
- (void)layoutSubviews{
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mas_top).with.offset(0);
make.left.equalTo(self.mas_left).with.offset(10);
make.right.equalTo(self.mas_right).with.offset(-10);
make.height.offset(30);
}];
}
- (void)clickedLoginBtn:(UIButton *)btn{
self.block?self.block(btn.tag):@"";
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end