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开发-实现快速登录弹窗与微信微博登录切换控件。
学习记录,每天不停进步。