This commit is contained in:
2025-11-12 21:23:31 +08:00
parent 0aead49816
commit bc261661ae
7 changed files with 317 additions and 24 deletions

View File

@@ -0,0 +1,143 @@
//
// KBLoginPopView.m
// LSTPopView 使
//
//
// - 使 Masonry iOS 13+ ASAuthorizationAppleIDButton
// -
//
#import "KBLoginPopView.h"
#import <Masonry/Masonry.h>
#import <AuthenticationServices/AuthenticationServices.h>
@interface KBLoginPopView ()
@property (nonatomic, strong) UILabel *titleLabel; //
@property (nonatomic, strong) UILabel *descLabel; // /
@property (nonatomic, strong) UIButton *closeButton; //
@property (nonatomic, strong) UIView *appleContainer; // Apple iOS13-
@end
@implementation KBLoginPopView
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor whiteColor];
self.layer.cornerRadius = 16.0;
self.layer.masksToBounds = YES;
[self setupUI];
}
return self;
}
#pragma mark - UI
//
- (void)setupUI {
[self addSubview:self.titleLabel];
[self addSubview:self.descLabel];
[self addSubview:self.appleContainer];
[self addSubview:self.closeButton];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self).offset(18);
make.left.equalTo(self).offset(16);
make.right.equalTo(self).offset(-16);
}];
[self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.titleLabel.mas_bottom).offset(6);
make.left.right.equalTo(self.titleLabel);
}];
[self.appleContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(16);
make.right.equalTo(self).offset(-16);
make.top.equalTo(self.descLabel.mas_bottom).offset(20);
make.height.mas_equalTo(52);
make.bottom.equalTo(self).offset(-24); //
}];
[self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self).offset(6);
make.right.equalTo(self).offset(-6);
make.width.height.mas_equalTo(36);
}];
// Apple
if (@available(iOS 13.0, *)) {
ASAuthorizationAppleIDButton *btn = [ASAuthorizationAppleIDButton new];
[btn addTarget:self action:@selector(onTapApple) forControlEvents:UIControlEventTouchUpInside];
[self.appleContainer addSubview:btn];
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.appleContainer);
}];
} else {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
[btn setTitle:@"需要 iOS13+ 才能使用 Apple 登录" forState:UIControlStateNormal];
btn.enabled = NO;
btn.layer.cornerRadius = 8.0;
btn.layer.borderWidth = 1.0;
btn.layer.borderColor = [UIColor lightGrayColor].CGColor;
[self.appleContainer addSubview:btn];
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.appleContainer);
}];
}
}
#pragma mark - Actions
// Apple
- (void)onTapApple {
if (self.appleLoginHandler) self.appleLoginHandler();
}
//
- (void)onTapClose {
if (self.closeHandler) self.closeHandler();
}
#pragma mark - Lazy
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [UILabel new];
_titleLabel.text = @"登录后可使用全部功能";
_titleLabel.font = [UIFont boldSystemFontOfSize:18];
_titleLabel.textColor = [UIColor blackColor];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.numberOfLines = 1;
}
return _titleLabel;
}
- (UILabel *)descLabel {
if (!_descLabel) {
_descLabel = [UILabel new];
_descLabel.text = @"我们将使用 Apple 进行快速安全登录";
_descLabel.font = [UIFont systemFontOfSize:14];
_descLabel.textColor = [UIColor colorWithWhite:0.2 alpha:0.8];
_descLabel.textAlignment = NSTextAlignmentCenter;
_descLabel.numberOfLines = 0;
}
return _descLabel;
}
- (UIButton *)closeButton {
if (!_closeButton) {
_closeButton = [UIButton buttonWithType:UIButtonTypeSystem];
[_closeButton setTitle:@"✕" forState:UIControlStateNormal];
[_closeButton setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal];
_closeButton.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
[_closeButton addTarget:self action:@selector(onTapClose) forControlEvents:UIControlEventTouchUpInside];
}
return _closeButton;
}
- (UIView *)appleContainer {
if (!_appleContainer) {
_appleContainer = [UIView new];
}
return _appleContainer;
}
@end