CNLiveThirdLoginView.m 2.82 KB
//
//  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