iOS开发-实现快速登录弹窗与微信微博QQ三方登录切换控件

iOS开发-实现快速登录弹窗与微信微博QQ三方登录切换控件。

之前开发中实现快速登录弹窗与微信微博等了切换控件。

一、效果图

在这里插入图片描述

二、实现代码

实现背景渐变UIBlurEffect

self.blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
self.effectView = [[UIVisualEffectView alloc] initWithEffect:self.blurEffect];

整体View添加到keyWindow

[[UIApplication sharedApplication].keyWindow addSubview:self];

显示与隐藏控件的弹性Spring动画

  • usingSpringWithDamping:为控制阻抑的量,逐渐减少,知道控件到达最终的位置。越接近于0.0,则表示越具有弹簧型
  • initialSpringVelocity:标示动画的初始速度

API

[UIView animateWithDuration:0.35 delay:0.0 usingSpringWithDamping:0.8 initialSpringVelocity:2.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.contentBGImageView.frame = contentBGFrame;
        self.alpha = 1.0;
    } completion:^(BOOL finished) {
        
    }];

2.1、快速登录控件

INFastLoginView.h声明显示与隐藏方法

#import <UIKit/UIKit.h>

@interface INFastLoginView : UIView

- (void)show;

- (void)dismiss;

@end

INFastLoginView.m具体实现

#import "INFastLoginView.h"
#import "UIColor+Addition.h"
#import "INFastLoginContentView.h"
#import "INFastLoginThirdView.h"

static CGFloat kContentPadding = 25.0;

static CGFloat kMidPadding = 10.0;

static CGFloat kCloseSize = 44.0;

static CGFloat kShowThirdSize = 36.0;

static CGFloat kTitleHeight = 44.0;

static CGFloat kButtonWidth = 88.0;

static CGFloat kButtonHeight = 40.0;

static CGFloat kInputBGHeight = 52.0;

@interface INFastLoginView ()<INFastLoginContentViewDelegate, INFastLoginThirdViewDelegate>

@property (nonatomic, strong) UIView *maskBGView;

@property (nonatomic, strong) UIImageView *contentBGImageView;
@property (nonatomic, strong) UIImageView *contentImageView;

@property (nonatomic, strong) UIBlurEffect *blurEffect;
@property (nonatomic, strong) UIVisualEffectView *effectView;

@property (nonatomic, strong) UIButton *closeButton;

@property (nonatomic, strong) INFastLoginContentView *loginContentView;

@property (nonatomic, strong) INFastLoginThirdView *thirdContentView;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIButton *loginButton;

@property (nonatomic, strong) UIButton *registerButton;

@property (nonatomic, strong) UIButton *showThirdButton;

@end

@implementation INFastLoginView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [[UIApplication sharedApplication].keyWindow addSubview:self];
        self.frame = [UIScreen mainScreen].bounds;
        
        self.maskBGView = [[UIApplication sharedApplication].keyWindow snapshotViewAfterScreenUpdates:NO];

        [self addSubview:self.maskBGView];
        [self addSubview:self.contentBGImageView];
        [self.contentBGImageView addSubview:self.contentImageView];
        [self.contentImageView addSubview:self.closeButton];
        
        self.blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
        self.effectView = [[UIVisualEffectView alloc] initWithEffect:self.blurEffect];
        [self.maskBGView addSubview:self.effectView];
        
        [self.contentImageView addSubview:self.titleLabel];
        [self.contentImageView addSubview:self.loginContentView];
        [self.contentImageView addSubview:self.loginButton];
        [self.contentImageView addSubview:self.registerButton];
        [self.contentImageView addSubview:self.thirdContentView];
        [self.contentImageView addSubview:self.showThirdButton];
        
        [self layoutContentSubViews];
        
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction)];
        [self.maskBGView addGestureRecognizer:tapGesture];
        
        self.hidden = YES;
        self.thirdContentView.hidden = YES;
        self.loginContentView.hidden = NO;
    }
    return self;
}

- (void)layoutContentSubViews {
    self.maskBGView.frame = self.bounds;
    self.effectView.frame = self.maskBGView.bounds;
    
    CGFloat width = (CGRectGetWidth(self.bounds) - kContentPadding*2);
    CGFloat height = 250.0;

    self.contentBGImageView.frame = CGRectMake(0.0, 0.0, width, height);
    self.contentBGImageView.center = self.center;
    
    self.contentImageView.frame = self.contentBGImageView.bounds;
    
    self.closeButton.frame = CGRectMake(CGRectGetWidth(self.contentImageView.frame) - kCloseSize - kMidPadding, kMidPadding, kCloseSize, kCloseSize);
    
    self.titleLabel.frame = CGRectMake(2*kMidPadding, kMidPadding, CGRectGetWidth(self.contentImageView.frame) - (kCloseSize + 4*kMidPadding), kTitleHeight);
    
    self.loginContentView.frame = CGRectMake(kMidPadding, CGRectGetMaxY(self.closeButton.frame) + kMidPadding, CGRectGetWidth(self.contentImageView.frame) - 2*kMidPadding, kInputBGHeight*2);
    
    self.loginButton.frame = CGRectMake(2*kMidPadding, CGRectGetMaxY(self.loginContentView.frame) + 2*kMidPadding, kButtonWidth, kButtonHeight);
    
    self.registerButton.frame = CGRectMake(CGRectGetMaxX(self.loginButton.frame) + kMidPadding, CGRectGetMaxY(self.loginContentView.frame) + 2*kMidPadding, kButtonWidth, kButtonHeight);

    self.thirdContentView.frame = CGRectMake(0.0, CGRectGetMaxY(self.titleLabel.frame), CGRectGetWidth(self.contentImageView.frame), CGRectGetHeight(self.contentImageView.frame) - CGRectGetMaxY(self.titleLabel.frame));
    
    self.showThirdButton.frame = CGRectMake(CGRectGetWidth(self.contentImageView.frame) - kShowThirdSize - kMidPadding, CGRectGetHeight(self.contentImageView.frame) - kShowThirdSize - kMidPadding, kShowThirdSize, kShowThirdSize);
}

- (void)show {
    self.hidden = NO;
    self.alpha = 0.0;
    
    CGRect contentBGFrame = self.contentBGImageView.frame;
    contentBGFrame.origin.y = - self.contentImageView.frame.size.height;
    self.contentBGImageView.frame = contentBGFrame;
    
    contentBGFrame.origin.y = (CGRectGetHeight(self.bounds) - contentBGFrame.size.height)/2;
    [UIView animateWithDuration:0.35 delay:0.0 usingSpringWithDamping:0.8 initialSpringVelocity:2.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.contentBGImageView.frame = contentBGFrame;
        self.alpha = 1.0;
    } completion:^(BOOL finished) {
        
    }];
}

- (void)dismiss {
    [self tapGestureAction];
    
    CGRect contentBGFrame = self.contentBGImageView.frame;
    contentBGFrame.origin.y = - self.contentImageView.frame.size.height;
    
    self.contentBGImageView.alpha = 0.0;
    [UIView animateWithDuration:0.35 delay:0.0 usingSpringWithDamping:0.8 initialSpringVelocity:2.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.contentBGImageView.frame = contentBGFrame;
        self.alpha = 0.0;
    } completion:^(BOOL finished) {
        self.hidden = YES;
        [self removeFromSuperview];
    }];
}

#pragma mark - TAP ACTIONS
- (void)tapGestureAction {
    // 发送resignFirstResponder.
    [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
}

#pragma mark - ACTIONS
/**
 关闭按钮
 */
- (void)closeButtonAction {
    [self dismiss];
}

/**
 展开显示第三方登录按钮
 */
- (void)showThirdButtonAction {
    [self tapGestureAction];
    
    UIViewAnimationOptions option;
    if (self.showThirdButton.selected) {
        option = UIViewAnimationOptionTransitionCurlUp;
    } else {
        option = UIViewAnimationOptionTransitionCurlUp;
    }
    
    if (!self.showThirdButton.selected) {
        self.thirdContentView.hidden = NO;
        self.thirdContentView.alpha = 1.0;
        
        CGRect thirdContentFrame = self.thirdContentView.frame;
        thirdContentFrame.size.height = 0.0;
        self.thirdContentView.frame = thirdContentFrame;
        
        thirdContentFrame.size.height = CGRectGetHeight(self.contentImageView.frame) - CGRectGetMaxY(self.titleLabel.frame);
        
        [UIView animateWithDuration:0.35 delay:0.0 options:option animations:^{
            self.thirdContentView.frame = thirdContentFrame;
            self.loginContentView.alpha = 0.0;
        } completion:^(BOOL finished) {
            self.thirdContentView.hidden = NO;
            self.loginContentView.hidden = YES;
        }];
    } else {
        self.loginContentView.hidden = NO;
        self.loginContentView.alpha = 0.0;
        [UIView animateWithDuration:0.35 delay:0.0 options:option animations:^{
            self.thirdContentView.alpha = 0.0;
            self.loginContentView.alpha = 1.0;
        } completion:^(BOOL finished) {
            self.thirdContentView.hidden = YES;
            self.thirdContentView.alpha = 1.0;
            self.loginContentView.hidden = NO;
        }];
    }
    
    self.showThirdButton.selected = !self.showThirdButton.selected;
}

/**
 登录按钮
 */
- (void)loginButtonAction {
    
}

/**
 去注册
 */
- (void)registerButtonAction {
    
}

#pragma mark - INFastLoginThirdViewDelegate第三方登录
/**
 微信登录
 */
- (void)weixinLoginButtonDidAction {
    
}

/**
 qq登录
 */
- (void)qqLoginButtonDidAction {
    
}

/**
 微博登录
 */
- (void)weiboLoginButtonDidAction {
    
}

#pragma mark - INFastLoginContentViewDelegate
- (void)keybroadShown:(CGFloat)keyboardHeight {
    CGRect contentBGFrame = self.contentBGImageView.frame;
    contentBGFrame.origin.y = CGRectGetHeight(self.bounds) - keyboardHeight - CGRectGetHeight(self.contentImageView.frame) - kMidPadding;
    
    [UIView animateWithDuration:0.35 delay:0.0 usingSpringWithDamping:0.8 initialSpringVelocity:2.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.contentBGImageView.frame = contentBGFrame;
    } completion:^(BOOL finished) {
        
    }];
}

- (void)keybroadHien:(CGFloat)keyboardHeight {
    CGRect contentBGFrame = self.contentBGImageView.frame;    
    contentBGFrame.origin.y = (CGRectGetHeight(self.bounds) - contentBGFrame.size.height)/2;
    [UIView animateWithDuration:0.35 delay:0.0 usingSpringWithDamping:0.8 initialSpringVelocity:2.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.contentBGImageView.frame = contentBGFrame;
    } completion:^(BOOL finished) {
        
    }];
}

#pragma mark - SETTER/GETTER
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _titleLabel.font = [UIFont systemFontOfSize:20];
        _titleLabel.textColor = [UIColor colorWithHexString:@"131619"];
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.text = @"快速登录";
    }
    
    return _titleLabel;
}

- (UIImageView *)contentBGImageView {
    if (!_contentBGImageView) {
        _contentBGImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        _contentBGImageView.userInteractionEnabled = YES;
        _contentBGImageView.backgroundColor = [UIColor clearColor];
        _contentBGImageView.layer.shadowColor = [UIColor colorWithHexString:@"9bb9ef"].CGColor;
        _contentBGImageView.layer.shadowOffset = CGSizeMake(0, 3);
        _contentBGImageView.layer.shadowOpacity = 0.3;
        _contentBGImageView.layer.shadowRadius = 3.0;
    }
    return _contentBGImageView;
}

- (UIImageView *)contentImageView {
    if (!_contentImageView) {
        _contentImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        _contentImageView.clipsToBounds = YES;
        _contentImageView.backgroundColor = [UIColor whiteColor];
        _contentImageView.layer.cornerRadius = 4;
        _contentImageView.layer.masksToBounds = YES;
        _contentImageView.userInteractionEnabled = YES;
    }
    return _contentImageView;
}

- (UIButton *)closeButton {
    if (!_closeButton) {
        _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeButton setImage:[UIImage imageNamed:@"ic_l_close"] forState:UIControlStateNormal];
        [_closeButton addTarget:self action:@selector(closeButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeButton;
}

- (UIButton *)showThirdButton {
    if (!_showThirdButton) {
        _showThirdButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_showThirdButton setImage:[UIImage imageNamed:@"ic_login_uparrow"] forState:UIControlStateNormal];
        [_showThirdButton setImage:[UIImage imageNamed:@"ic_login_downarrow"] forState:UIControlStateSelected];
        [_showThirdButton addTarget:self action:@selector(showThirdButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _showThirdButton;
}

- (INFastLoginContentView *)loginContentView {
    if (!_loginContentView) {
        _loginContentView = [[INFastLoginContentView alloc] initWithFrame:self.contentImageView.bounds];
        _loginContentView.backgroundColor = [UIColor whiteColor];
        _loginContentView.delegate = self;
        _loginContentView.clipsToBounds = YES;
    }
    return _loginContentView;
}

- (INFastLoginThirdView *)thirdContentView {
    if (!_thirdContentView) {
        _thirdContentView = [[INFastLoginThirdView alloc] initWithFrame:self.contentImageView.bounds];
        _thirdContentView.backgroundColor = [UIColor whiteColor];
        _thirdContentView.delegate = self;
        _thirdContentView.clipsToBounds = YES;
    }
    return _thirdContentView;
}

- (UIButton *)loginButton {
    if (!_loginButton) {
        _loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_loginButton setTitle:@"登录" forState:UIControlStateNormal];
        [_loginButton setTitleColor:[UIColor colorWithHexString:@"131619"] forState:UIControlStateNormal];
        [_loginButton addTarget:self action:@selector(loginButtonAction) forControlEvents:UIControlEventTouchUpInside];
        _loginButton.titleLabel.font = [UIFont systemFontOfSize:18];
    }
    return _loginButton;
}

- (UIButton *)registerButton {
    if (!_registerButton) {
        _registerButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_registerButton setTitle:@"去注册" forState:UIControlStateNormal];
        [_registerButton setTitleColor:[UIColor colorWithHexString:@"ff7e48"] forState:UIControlStateNormal];
        [_registerButton addTarget:self action:@selector(registerButtonAction) forControlEvents:UIControlEventTouchUpInside];
        _registerButton.titleLabel.font = [UIFont systemFontOfSize:15];
    }
    return _registerButton;
}

@end

2.1、当点击按钮进行切换账号密码登录

账号密码登录控件,实现输入框与注册按钮布局.

INFastLoginContentView.h

#import <UIKit/UIKit.h>

@protocol INFastLoginContentViewDelegate;
@interface INFastLoginContentView : UIView

@property (nonatomic, weak) id<INFastLoginContentViewDelegate>delegate;

@end

@protocol INFastLoginContentViewDelegate <NSObject>

- (void)keybroadShown:(CGFloat)keyboardHeight;

- (void)keybroadHien:(CGFloat)keyboardHeight;

@end

INFastLoginContentView.m

#import "INFastLoginContentView.h"
#import "UIColor+Addition.h"

static CGFloat kInputHeight = 44.0;
static CGFloat kMidPadding = 6.0;
static CGFloat kMidSmallPadding = 5.0;
static CGFloat kLineHeight = 1.0;

@interface INFastLoginContentView ()<UITextFieldDelegate>

@property (nonatomic, strong) UIImageView *phoneBGImageView;
@property (nonatomic, strong) UIImageView *phoneLineImageView;

@property (nonatomic, strong) UIImageView *pwdBGImageView;
@property (nonatomic, strong) UIImageView *pwdLineImageView;

@property (nonatomic, strong) UITextField *phoneTextField;
@property (nonatomic, strong) UITextField *pwdTextField;

@property (nonatomic, assign) CGFloat keyboardHeight;

@end

@implementation INFastLoginContentView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.phoneBGImageView];
        [self addSubview:self.pwdBGImageView];
        [self.phoneBGImageView addSubview:self.phoneTextField];
        [self.pwdBGImageView addSubview:self.pwdTextField];
        
        [self.phoneBGImageView addSubview:self.phoneLineImageView];
        [self.pwdBGImageView addSubview:self.pwdLineImageView];
        
        [self addObservers];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.phoneBGImageView.frame = CGRectMake(kMidPadding, kMidPadding, CGRectGetWidth(self.bounds) - 2*kMidPadding, kInputHeight);
    
    self.pwdBGImageView.frame = CGRectMake(kMidPadding, CGRectGetMaxY(self.phoneBGImageView.frame) + kMidPadding, CGRectGetWidth(self.bounds) - 2*kMidPadding, kInputHeight);
    
    self.phoneTextField.frame = CGRectMake(kMidSmallPadding, 0.0, CGRectGetWidth(self.phoneBGImageView.frame) - 2*kMidSmallPadding, kInputHeight);
    
    self.pwdTextField.frame = CGRectMake(kMidSmallPadding, 0.0, CGRectGetWidth(self.phoneBGImageView.frame) - 2*kMidSmallPadding, kInputHeight);
    
    self.phoneLineImageView.frame = CGRectMake(0.0, CGRectGetHeight(self.phoneBGImageView.frame) - kLineHeight, CGRectGetWidth(self.phoneBGImageView.frame), kLineHeight);
    
    self.pwdLineImageView.frame = CGRectMake(0.0, CGRectGetHeight(self.pwdBGImageView.frame) - kLineHeight, CGRectGetWidth(self.pwdBGImageView.frame), kLineHeight);
}

#pragma mark - Observers
- (void)addObservers {
    //监听键盘出现、消失
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

- (void)removeObervers {
    //监听键盘出现、消失
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


#pragma mark - 键盘将要出现
- (void)keyboardWillShow:(NSNotification *)notification {
    NSDictionary *userInfo = notification.userInfo;
    CGRect endFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    //获取键盘的高度
    self.keyboardHeight = endFrame.size.height;
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(keybroadShown:)]) {
        [self.delegate keybroadShown:self.keyboardHeight];
    }
}

#pragma mark - 键盘将要消失
- (void)keyboardWillHide:(NSNotification *)notification {
    self.keyboardHeight = 0.0;
    if (self.delegate && [self.delegate respondsToSelector:@selector(keybroadHien:)]) {
        [self.delegate keybroadHien:self.keyboardHeight];
    }
}

#pragma mark - SETTER/GETTER
- (UIImageView *)phoneBGImageView {
    if (!_phoneBGImageView) {
        _phoneBGImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        _phoneBGImageView.userInteractionEnabled = YES;
    }
    return _phoneBGImageView;
}

- (UIImageView *)pwdBGImageView {
    if (!_pwdBGImageView) {
        _pwdBGImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        _pwdBGImageView.userInteractionEnabled = YES;
    }
    return _pwdBGImageView;
}

- (UIImageView *)phoneLineImageView {
    if (!_phoneLineImageView) {
        _phoneLineImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        _phoneLineImageView.backgroundColor = [UIColor colorWithHexString:@"efefef"];
        _phoneLineImageView.layer.shadowColor = [UIColor colorWithHexString:@"9bb9ef"].CGColor;
        _phoneLineImageView.layer.shadowOffset = CGSizeMake(0, 3);
        _phoneLineImageView.layer.shadowOpacity = 0.3;
        _phoneLineImageView.layer.shadowRadius = 3.0;
    }
    return _phoneLineImageView;
}

- (UIImageView *)pwdLineImageView {
    if (!_pwdLineImageView) {
        _pwdLineImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        _pwdLineImageView.backgroundColor = [UIColor colorWithHexString:@"efefef"];
        _pwdLineImageView.layer.shadowColor = [UIColor colorWithHexString:@"9bb9ef"].CGColor;
        _pwdLineImageView.layer.shadowOffset = CGSizeMake(0, 3);
        _pwdLineImageView.layer.shadowOpacity = 0.3;
        _pwdLineImageView.layer.shadowRadius = 3.0;
    }
    return _pwdLineImageView;
}

- (UITextField *)phoneTextField {
    if (!_phoneTextField) {
        _phoneTextField = [[UITextField alloc] initWithFrame:CGRectZero];
        _phoneTextField.backgroundColor = [UIColor clearColor];
        _phoneTextField.clipsToBounds = YES;
        _phoneTextField.textColor = [UIColor colorWithAlphaFromHex:@"131619"];
        _phoneTextField.font = [UIFont systemFontOfSize:16.0];
        _phoneTextField.placeholder = @"输入手机号";
        _phoneTextField.delegate = self;
        _phoneTextField.keyboardType = UIKeyboardTypeDefault;
        _phoneTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
        _phoneTextField.returnKeyType = UIReturnKeySearch;
    }
    return _phoneTextField;
}

- (UITextField *)pwdTextField {
    if (!_pwdTextField) {
        _pwdTextField = [[UITextField alloc] initWithFrame:CGRectZero];
        _pwdTextField.backgroundColor = [UIColor clearColor];
        _pwdTextField.clipsToBounds = YES;
        _pwdTextField.textColor = [UIColor colorWithAlphaFromHex:@"131619"];
        _pwdTextField.font = [UIFont systemFontOfSize:16.0];
        _pwdTextField.placeholder = @"输入密码";
        _pwdTextField.delegate = self;
        _pwdTextField.keyboardType = UIKeyboardTypeDefault;
        _pwdTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
        _pwdTextField.returnKeyType = UIReturnKeySearch;
    }
    return _pwdTextField;
}

@end

2.2、实现微信微博QQ登录按钮排列

实现微信微博QQ登录按钮排列,三方登录按钮排列效果如下

INFastLoginThirdView.h

#import <UIKit/UIKit.h>

/**
 第三方登录控件
 */
@protocol INFastLoginThirdViewDelegate;
@interface INFastLoginThirdView : UIView

@property (nonatomic, weak) id<INFastLoginThirdViewDelegate>delegate;

@end

@protocol INFastLoginThirdViewDelegate <NSObject>

- (void)weixinLoginButtonDidAction;

- (void)qqLoginButtonDidAction;

- (void)weiboLoginButtonDidAction;

@end

INFastLoginThirdView.m

#import "INFastLoginThirdView.h"
#import "UIColor+Addition.h"

static CGFloat kPadding = 15.0;
static CGFloat kTitleHeight = 50.0;
static CGFloat kButtonSize = 40.0;

@interface INFastLoginThirdView ()

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIButton *weiboButton;
@property (nonatomic, strong) UIButton *qqButton;
@property (nonatomic, strong) UIButton *weixinButton;

@end

@implementation INFastLoginThirdView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.titleLabel];
        [self addSubview:self.weiboButton];
        [self addSubview:self.weixinButton];
        [self addSubview:self.qqButton];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.titleLabel.frame = CGRectMake(kPadding, 0.0, CGRectGetWidth(self.bounds) - 2*kPadding, kTitleHeight);
    
    CGFloat height = CGRectGetHeight(self.bounds) - 2*CGRectGetMaxY(self.titleLabel.frame) - kPadding;
    CGFloat originY = CGRectGetMaxY(self.titleLabel.frame) + (height - kButtonSize)/2;
    CGFloat originX = (CGRectGetWidth(self.bounds) - 2*kPadding - 3*kButtonSize)/4;

    self.weiboButton.frame = CGRectMake(kPadding + originX, originY, kButtonSize, kTitleHeight);
    self.weixinButton.frame = CGRectMake(CGRectGetMaxX(self.weiboButton.frame) + originX, originY, kButtonSize, kButtonSize);
    self.qqButton.frame = CGRectMake(CGRectGetMaxX(self.weixinButton.frame) + originX, originY, kButtonSize, kButtonSize);
}

#pragma mark - BUTTON ACTIONS
- (void)weiboButtonAction {
    if (self.delegate && [self.delegate respondsToSelector:@selector(weiboLoginButtonDidAction)]) {
        [self.delegate weiboLoginButtonDidAction];
    }
}

- (void)qqButtonAction {
    if (self.delegate && [self.delegate respondsToSelector:@selector(qqLoginButtonDidAction)]) {
        [self.delegate qqLoginButtonDidAction];
    }
}

- (void)weixinButtonAction {
    if (self.delegate && [self.delegate respondsToSelector:@selector(weixinLoginButtonDidAction)]) {
        [self.delegate weixinLoginButtonDidAction];
    }
}

#pragma mark - SETTER/GETTER
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.textColor = [UIColor colorWithHexString:@"9a9b9c"];
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.text = @"使用第三方账户登录";
    }
    
    return _titleLabel;
}

- (UIButton *)weiboButton {
    if (!_weiboButton) {
        _weiboButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_weiboButton setImage:[UIImage imageNamed:@"ic_login_weibo"] forState:UIControlStateNormal];
        _weiboButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
        [_weiboButton addTarget:self action:@selector(weiboButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weiboButton;
}

- (UIButton *)qqButton {
    if (!_qqButton) {
        _qqButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_qqButton setImage:[UIImage imageNamed:@"ic_login_qq"] forState:UIControlStateNormal];
        _qqButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
        [_qqButton addTarget:self action:@selector(qqButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _qqButton;
}

- (UIButton *)weixinButton {
    if (!_weixinButton) {
        _weixinButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_weixinButton setImage:[UIImage imageNamed:@"ic_login_weixin"] forState:UIControlStateNormal];
        _weixinButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
        [_weixinButton addTarget:self action:@selector(weixinButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weixinButton;
}


@end

三、小结

iOS开发-实现快速登录弹窗与微信微博登录切换控件。

学习记录,每天不停进步。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/49618.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

linux上适用的反汇编调试软件(对标od)

ubuntu下类似于od软件 经过搜索&#xff0c;在Ubuntu上选用edb-debugger进行动态调试&#xff0c; 下载链接: https://github.com/eteran/edb-debugger 但是依赖反汇编引擎: https://github.com/capstone-engine/capstone 安装 先安装capstone 先下载release的版本&#xf…

基于量子同态加密的安全多方凸包协议

摘要安全多方计算几何(SMCG)是安全多方计算的一个分支。该协议是为SMCG中安全的多方凸包计算而设计的。首先&#xff0c;提出了一种基于量子同态加密的安全双方值比较协议。由于量子同态加密的性质&#xff0c;该协议可以很好地保护量子电路执行过程中数据的安全性和各方之间的…

组合模式-树形结构的处理

A公司需要筛选出年龄35岁及以上(如果是领导&#xff0c;年龄为45岁及以上)的人。其组织架构图如下。 图 A公司部分组织架构图 图 传统解决方案 public class Development {private String name;public Development(String name) {this.name name;}List<Employee> emplo…

需求分析案例:消息配置中心

本文介绍了一个很常见的消息推送需求&#xff0c;在系统需要短信、微信、邮件之类的消息推送时&#xff0c;边界如何划分和如何设计技术方案。 1、需求 一个系统&#xff0c;一般会区分多个业务模块&#xff0c;并拆分成不同的业务系统&#xff0c;例如一个商城的架构如下&am…

flutter(01) windows桌面版 编译环境安装指南

1 flutter环境安装 flutter官网参考&#xff1a;Install | Flutter 先下载flutter SDK>&#xff1a;flutter sdk下载--官网&#xff0c;之后解压到C:\Users\XXX\data&#xff08;这里以该路径为例&#xff0c;但可以为其他自定义路径&#xff09;目录下&#xff0c;在这里…

栈和队列模拟实现(C++)

文章目录 0.码云完整代码1.deque的认识1.1介绍1.2图析1.3性能比较 2.stack的学习2.1模拟实现2.2测试函数 3.queue的学习3.1模拟实现3.2测试函数 4.优先级队列的学习4.0仿函数的引入4.1介绍4.2例题4.3模拟实现 5.测试函数 0.码云完整代码 点击 栈 队列 优先级队列 跳转码云获取…

鸿鹄协助管理华为云与炎凰Ichiban

炎凰对华为云的需求 在炎凰日常的开发中&#xff0c;对于服务器上的需求&#xff0c;我们基本都是采用云服务。目前我们主要选择的是华为云&#xff0c;华为云的云主机比较稳定&#xff0c;提供的云主机配置也比较多样&#xff0c;非常适合对于不同场景硬件配置的需求&#xff…

石子合并(区间dp模板)

题目描述&#xff1a; dp分析&#xff1a; 解题代码&#xff1a; #include<iostream> using namespace std;const int N1e36;int f[N][N]; int a[N]; int s[N];int main(){int n;cin>>n;for(int i1;i<n;i){scanf("%d",&s[i]);s[i]s[i-1];//前缀和…

2.1数据结构——线性表

一、定义 线性表是具有相同数据类型的n&#xff08;n>0&#xff09;个数据元素的有限序列&#xff0c;&#xff08;n表示表长&#xff0c;n0为空表&#xff09; 用L表示&#xff1a; 位序&#xff1a;线性表中的“第i个” a1是表头元素&#xff1b;an是表尾元素 除第一个…

《吐血整理》进阶系列教程-拿捏Fiddler抓包教程(8)-Fiddler如何设置捕获会话

1.简介 前边几篇宏哥介绍了Fiddler界面内容以及作用。今天宏哥就讲解和分享如何设置Fiddler后&#xff0c;我们就可以捕获会话&#xff0c;进行抓包了。 2.捕获会话的设备 常见的捕获会话的设备分为PC&#xff08;电脑&#xff09;端和手机&#xff08;Android和IOS苹果&…

【SpringⅢ】Spring 的生命周期

目录 &#x1f96a;1 Bean 的作用域 &#x1f969;1.1 singleton&#xff1a;单例模式 &#x1f359;1.2 prototype&#xff1a;原型模式 &#x1f371;1.3 Bean 的其他作用域 &#x1f35c;2 Spring 生命周期(执行流程) &#x1f958;2.1 启动容器 &#x1f372; 2.2 读…

Elasticsearch:使用 ELSER 释放语义搜索的力量:Elastic Learned Sparse EncoderR

问题陈述 在信息过载的时代&#xff0c;根据上下文含义和用户意图而不是精确的关键字匹配来查找相关搜索结果已成为一项重大挑战。 传统的搜索引擎通常无法理解用户查询的语义上下文&#xff0c;从而导致相关性较低的结果。 解决方案&#xff1a;ELSER Elastic 通过其检索模型…

vue elementui table去掉滚动条与实现表格自动滚动且无滚动条

当table内容列过多时&#xff0c;可通过height属性设置table高度以固定table高度、固定表头&#xff0c;使table内容可以滚动。 现在需求是右侧滚动条不好看&#xff0c;需要去除滚动条&#xff0c;并隐藏滚动条所占列的位置。让他可以滚动但是不出现滚动条,不然即时隐藏了滚动…

Mybatis学习笔记

Mybatis 文章目录 Mybatis搭建环境创建Maven工程将数据库中的表转换为对应的实体类配置文件核心配置文件mybatis-config.xml创建Mapper接口映射文件xxxMapper.xmllog4j日志功能 Mybatis操纵数据库示例及要点说明获取参数的两种方式${}#{} 各种类型的参数处理单个字面量参数多个…

keil官网下载MDK的STM32芯片pack包

背景 最近重装了电脑系统&#xff0c;重新安装了MDK所以导致MDK芯片包需要重新下载&#xff0c;软件内下载又太慢&#xff0c;所以趁现在找到了官网下载方法把方法分享出来供大家参考。 1、在浏览器中输入网址&#xff1a;www.keil.arm.com进入如下界面&#xff0c;然后点击&am…

Mock-MOCO使用过程

一、jar包下载&#xff1a;https://github.com/dreamhead/moco 二、准备mock的json文件 data.json内容&#xff1a; ####GET请求 [{"description": "response使用Content-Type为charsetGBK编码格式来查看返回信息为中文的内容","request": {&q…

Tensorflow预训练模型ckpt与pb两种文件类型的介绍

我们在 Tensorflow无人车使用移动端的SSD(单发多框检测)来识别物体及Graph的认识 熟悉了Graph计算图以及在 Tensorflow2.0中function(是1.0版本的Graph的推荐替代)的相关知识介绍 这个tf.function的用法&#xff0c;了解到控制流与计算图的各自作用&#xff0c;无论使用哪种方…

Linux基本指令操作

登陆指令&#xff08;云服务器版&#xff09; 当我们获取公网IP地址后&#xff0c;我们就可以打开xshell。 此时会有这样的界面&#xff0c;我们若是想的登陆&#xff0c;则需要输入以下的指令 ssh 用户名公网IP地址 然后会跳出以下的窗口 接着输入密码——密码便是先前定好…

利用小波包对一维信号进行降噪或压缩(MATLAB)

function [ output_args ] example4_12( input_args ) %EXAMPLE4_12 Summary of this function goes here % Detailed explanation goes here clc; clear; % 设置信噪比和随机数的初始值 snr 3; init 2055615866; % 生成一个原始信号xref和含高斯白噪声的信号x [xref,x] …

微服务契约测试框架-Pact

契约测试 契约测试的思想就是将原本的 Consumer 与 Provider 间同步的集成测试&#xff0c;通过契约进行解耦&#xff0c;变成 Consumer 与 Provider 端两个各自独立的、异步的单元测试。 契约测试的优点&#xff1a; 契约测试与单元测试以及其它测试之间没有重复&#xff0c…