增加换肤功能
This commit is contained in:
17
QXLive/Tabbar/TabbarCustomView/CustomVersionUpdateView.h
Executable file
17
QXLive/Tabbar/TabbarCustomView/CustomVersionUpdateView.h
Executable file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// CustomVersionUpdateView.h
|
||||
// SoundRiver
|
||||
//
|
||||
// Created by y1758946235 on 2020/2/17.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface CustomVersionUpdateView : UIView
|
||||
|
||||
-(void)getDownloadUrl:(NSString *)downloadUrl isForceUpdate:(NSString *)ForceUpdate;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
87
QXLive/Tabbar/TabbarCustomView/CustomVersionUpdateView.m
Executable file
87
QXLive/Tabbar/TabbarCustomView/CustomVersionUpdateView.m
Executable file
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// CustomVersionUpdateView.m
|
||||
// SoundRiver
|
||||
//
|
||||
// Created by y1758946235 on 2020/2/17.
|
||||
//
|
||||
|
||||
#import "CustomVersionUpdateView.h"
|
||||
@interface CustomVersionUpdateView ()
|
||||
@property (nonatomic, strong) UIButton *centerBgBtn;
|
||||
@property (nonatomic, copy) NSString *downloadUrl;
|
||||
@end
|
||||
@implementation CustomVersionUpdateView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
self.backgroundColor = RGBA(0, 0, 0, 0.5);
|
||||
[self centerBgBtn];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)tapClick {
|
||||
[self removeFromSuperview];
|
||||
}
|
||||
|
||||
- (void)getDownloadUrl:(NSString *)downloadUrl isForceUpdate:(NSString *)ForceUpdate {
|
||||
self.downloadUrl = downloadUrl;
|
||||
if ([ForceUpdate intValue] != 1) {
|
||||
self.userInteractionEnabled = YES;
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick)];
|
||||
[self addGestureRecognizer:tap];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Getter
|
||||
|
||||
- (NSString *)downloadUrl
|
||||
{
|
||||
if (!_downloadUrl) {
|
||||
_downloadUrl = [[NSString alloc] init];
|
||||
}
|
||||
return _downloadUrl;
|
||||
}
|
||||
|
||||
- (UIButton *)centerBgBtn
|
||||
{
|
||||
if (!_centerBgBtn) {
|
||||
_centerBgBtn = [[UIButton alloc] initWithFrame:CGRectZero];
|
||||
[_centerBgBtn setBackgroundImage:[UIImage imageNamed:@"sr_update_version"] forState:UIControlStateNormal];
|
||||
[_centerBgBtn setBackgroundImage:[UIImage imageNamed:@"sr_update_version"] forState:UIControlStateHighlighted];
|
||||
[_centerBgBtn addTarget:self action:@selector(updateClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
// UIView *view = [QuickCreatUI creatUIViewWithSuperView:_centerBgBtn andFrame:CGRectZero color:UIColor.redColor];
|
||||
[self addSubview:_centerBgBtn];
|
||||
[_centerBgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(0);
|
||||
make.centerY.mas_equalTo(0);
|
||||
make.size.mas_equalTo(CGSizeMake(ScaleWidth(305), ScaleWidth(345)));
|
||||
}];
|
||||
// [view mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
// make.centerX.mas_equalTo(0);
|
||||
// make.centerY.mas_equalTo(0);
|
||||
// make.size.mas_equalTo(CGSizeMake(AUTO_CEIL_WIETH(305), AUTO_CEIL_WIETH(40)));
|
||||
// }];
|
||||
}
|
||||
return _centerBgBtn;
|
||||
}
|
||||
|
||||
- (void)updateClick {
|
||||
if (@available(iOS 10.0, *)) {
|
||||
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.downloadUrl] options:@{} completionHandler:nil];
|
||||
} else {
|
||||
// Fallback on earlier versions
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// Only override drawRect: if you perform custom drawing.
|
||||
// An empty implementation adversely affects performance during animation.
|
||||
- (void)drawRect:(CGRect)rect {
|
||||
// Drawing code
|
||||
}
|
||||
*/
|
||||
|
||||
@end
|
||||
24
QXLive/Tabbar/TabbarCustomView/DrayView.h
Executable file
24
QXLive/Tabbar/TabbarCustomView/DrayView.h
Executable file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// DrayView.h
|
||||
// SoundRiver
|
||||
//
|
||||
// Created by apple on 2020/1/18.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "FLImageView.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DrayView : UIView
|
||||
@property (nonatomic, strong) FLImageView *animationView;
|
||||
|
||||
@property (nonatomic,copy) dispatch_block_t onGotoRoomBtnCallBack;
|
||||
@property (nonatomic,copy) dispatch_block_t onLeaveRoomBtnCallBack;
|
||||
|
||||
// 靠右边
|
||||
- (void)keepRightViewStatus;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
205
QXLive/Tabbar/TabbarCustomView/DrayView.m
Executable file
205
QXLive/Tabbar/TabbarCustomView/DrayView.m
Executable file
@@ -0,0 +1,205 @@
|
||||
//
|
||||
// DrayView.m
|
||||
// SoundRiver
|
||||
//
|
||||
// Created by apple on 2020/1/18.
|
||||
//
|
||||
|
||||
#import "DrayView.h"
|
||||
|
||||
@interface DrayView ()
|
||||
@property (nonatomic, strong) UIImageView *bgImgView;
|
||||
@property (nonatomic, strong) UIButton *tapBtn;
|
||||
@property (nonatomic, strong) UIButton *closeBtn;
|
||||
@property (nonatomic, strong) UIView *lineView;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation DrayView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
//添加拖拽手势-改变控件的位置
|
||||
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(changePostion:)];
|
||||
[self addGestureRecognizer:pan];
|
||||
[self setHidden:YES];
|
||||
|
||||
[self addSubview:self.bgImgView];
|
||||
[self addSubview:self.animationView];
|
||||
[self addSubview:self.tapBtn];
|
||||
[self addSubview:self.closeBtn];
|
||||
[self addSubview:self.lineView];
|
||||
|
||||
[self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self);
|
||||
}];
|
||||
[self.animationView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(2);
|
||||
make.centerY.equalTo(self);
|
||||
make.width.height.mas_equalTo(46);
|
||||
}];
|
||||
[self.tapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self.animationView);
|
||||
}];
|
||||
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(70);
|
||||
make.centerY.equalTo(self);
|
||||
make.width.height.mas_equalTo(25);
|
||||
}];
|
||||
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.bottom.equalTo(self).inset(15);
|
||||
make.left.mas_equalTo(60);
|
||||
make.width.mas_offset(1);
|
||||
}];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Btn Click
|
||||
- (void)onTapBtnClick:(UIButton *)btn {
|
||||
if (self.onGotoRoomBtnCallBack) {
|
||||
self.onGotoRoomBtnCallBack();
|
||||
}
|
||||
}
|
||||
- (void)onLeaveRoomBtnClick:(UIButton *)btn {
|
||||
if (self.onLeaveRoomBtnCallBack) {
|
||||
self.onLeaveRoomBtnCallBack();
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Getter
|
||||
- (UIImageView *)bgImgView {
|
||||
if (!_bgImgView) {
|
||||
_bgImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabbar_live_room_play_bg_tip"]];
|
||||
}
|
||||
return _bgImgView;
|
||||
}
|
||||
- (FLImageView *)animationView {
|
||||
if (!_animationView) {
|
||||
_animationView = [[FLImageView alloc] init];
|
||||
_animationView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
_animationView.layer.masksToBounds = YES;
|
||||
_animationView.layer.cornerRadius = 23;
|
||||
}
|
||||
return _animationView;
|
||||
}
|
||||
- (UIButton *)tapBtn {
|
||||
if (!_tapBtn) {
|
||||
_tapBtn = [[UIButton alloc] init];
|
||||
// _tapBtn.needEventInterval = 0.5;
|
||||
// [_tapBtn hx_setEnlargeEdgeWithTop:5 right:5 bottom:5 left:5];
|
||||
[_tapBtn addTarget:self action:@selector(onTapBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _tapBtn;
|
||||
}
|
||||
- (UIButton *)closeBtn {
|
||||
if (!_closeBtn) {
|
||||
_closeBtn = [[UIButton alloc] init];
|
||||
[_closeBtn setImage:[UIImage imageNamed:@"tabbar_live_close_btn"] forState:UIControlStateNormal];
|
||||
// _closeBtn.needEventInterval = 0.5;
|
||||
// [_closeBtn hx_setEnlargeEdgeWithTop:5 right:5 bottom:5 left:5];
|
||||
[_closeBtn addTarget:self action:@selector(onLeaveRoomBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _closeBtn;
|
||||
}
|
||||
|
||||
- (UIView *)lineView {
|
||||
if (!_lineView) {
|
||||
_lineView = [[UIView alloc] init];
|
||||
_lineView.backgroundColor = UIColor.whiteColor;
|
||||
}
|
||||
return _lineView;
|
||||
}
|
||||
|
||||
#pragma mark - Other
|
||||
// 靠右边
|
||||
- (void)keepRightViewStatus {
|
||||
self.bgImgView.transform = CGAffineTransformIdentity;
|
||||
|
||||
[self.animationView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(2);
|
||||
make.centerY.equalTo(self);
|
||||
make.width.height.mas_equalTo(46);
|
||||
}];
|
||||
[self.closeBtn mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(70);
|
||||
}];
|
||||
[self.lineView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(60);
|
||||
}];
|
||||
}
|
||||
// 靠左边
|
||||
- (void)keepLeftViewStatus {
|
||||
self.bgImgView.transform = CGAffineTransformMakeRotation(M_PI);
|
||||
|
||||
[self.animationView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(-2);
|
||||
make.centerY.equalTo(self);
|
||||
make.width.height.mas_equalTo(46);
|
||||
}];
|
||||
[self.closeBtn mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(5);
|
||||
}];
|
||||
[self.lineView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(35);
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - UIPanGestureRecognizer
|
||||
- (void)changePostion:(UIPanGestureRecognizer *)pan{
|
||||
CGPoint point = [pan translationInView:self];
|
||||
CGRect originalFrame = self.frame;
|
||||
originalFrame = [self changeXWithFrame:originalFrame point:point];
|
||||
originalFrame = [self changeYWithFrame:originalFrame point:point];
|
||||
self.frame = originalFrame;
|
||||
[pan setTranslation:CGPointZero inView:self];
|
||||
|
||||
UIButton *button = (UIButton *)pan.view;
|
||||
if (pan.state == UIGestureRecognizerStateBegan) {
|
||||
button.enabled = NO;
|
||||
}else if (pan.state == UIGestureRecognizerStateChanged){
|
||||
} else {
|
||||
CGRect frame = self.frame;
|
||||
if (self.center.x <= SCREEN_WIDTH / 2.0){
|
||||
frame.origin.x = 0;
|
||||
[self keepLeftViewStatus];
|
||||
}else {
|
||||
frame.origin.x = SCREEN_WIDTH - frame.size.width;
|
||||
[self keepRightViewStatus];
|
||||
}
|
||||
if (frame.origin.y < NavContentHeight) {
|
||||
frame.origin.y = NavContentHeight;
|
||||
} else if (frame.origin.y + frame.size.height > SCREEN_HEIGHT - NavContentHeight - TabbarHeight) {
|
||||
frame.origin.y = SCREEN_WIDTH - NavContentHeight - TabbarHeight - frame.size.height;
|
||||
}
|
||||
[UIView animateWithDuration:0.3 animations:^{
|
||||
self.frame = frame;
|
||||
}];
|
||||
button.enabled = YES;
|
||||
}
|
||||
}
|
||||
|
||||
//拖动改变控件的水平方向x值
|
||||
- (CGRect)changeXWithFrame:(CGRect)originalFrame point:(CGPoint)point{
|
||||
BOOL q1 = originalFrame.origin.x >= 0;
|
||||
BOOL q2 = originalFrame.origin.x + originalFrame.size.width <= SCREEN_WIDTH;
|
||||
if (q1 && q2) {
|
||||
originalFrame.origin.x += point.x;
|
||||
}
|
||||
return originalFrame;
|
||||
}
|
||||
|
||||
//拖动改变控件的竖直方向y值
|
||||
- (CGRect)changeYWithFrame:(CGRect)originalFrame point:(CGPoint)point{
|
||||
BOOL q1 = originalFrame.origin.y >= 20;
|
||||
BOOL q2 = originalFrame.origin.y + originalFrame.size.height <= SCREEN_HEIGHT;
|
||||
if (q1 && q2) {
|
||||
originalFrame.origin.y += point.y;
|
||||
}
|
||||
return originalFrame;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
21
QXLive/Tabbar/TabbarCustomView/FLImageView.h
Executable file
21
QXLive/Tabbar/TabbarCustomView/FLImageView.h
Executable file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// FLImageView.h
|
||||
// SoundRiver
|
||||
//
|
||||
// Created by ln007 on 2019/4/27.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface FLImageView : UIImageView {
|
||||
CABasicAnimation *_rotateAnimation;
|
||||
}
|
||||
|
||||
- (void)startRotating;
|
||||
- (void)stopRotating;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
29
QXLive/Tabbar/TabbarCustomView/FLImageView.m
Executable file
29
QXLive/Tabbar/TabbarCustomView/FLImageView.m
Executable file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// FLImageView.m
|
||||
// SoundRiver
|
||||
//
|
||||
// Created by ln007 on 2019/4/27.
|
||||
//
|
||||
|
||||
#import "FLImageView.h"
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
@implementation FLImageView
|
||||
- (void)startRotating {
|
||||
if (!_rotateAnimation) {
|
||||
CABasicAnimation *rotateAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
|
||||
rotateAnimation.fromValue = [NSNumber numberWithFloat:0.0];
|
||||
rotateAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2]; //旋转一周
|
||||
rotateAnimation.duration = 20.0; //旋转时间 20秒
|
||||
rotateAnimation.repeatCount = MAXFLOAT; //重复次数,这里使用最大次数
|
||||
_rotateAnimation = rotateAnimation;
|
||||
rotateAnimation.removedOnCompletion = NO;
|
||||
}
|
||||
[self.layer addAnimation:_rotateAnimation forKey:nil];
|
||||
}
|
||||
|
||||
- (void)stopRotating {
|
||||
[self.layer removeAllAnimations];
|
||||
}
|
||||
|
||||
@end
|
||||
39
QXLive/Tabbar/TabbarCustomView/QXTabBar.h
Normal file
39
QXLive/Tabbar/TabbarCustomView/QXTabBar.h
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// QXTabBar.h
|
||||
// FreeTabbar_JoeJin
|
||||
//
|
||||
// Created by J-Mac on 2024/5/24.
|
||||
// Copyright © 2024 JoeJin-QQ:853105953. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <Masonry/Masonry.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class QXTabBar,QXTabbarConfig;
|
||||
|
||||
@protocol QXTabBarDelegate <NSObject>
|
||||
|
||||
@optional
|
||||
- (void)QXTabBar:(QXTabBar *)tabBar didSelectedButtonFrom:(NSInteger)from to:(NSInteger)to;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@interface QXTabBar : UIView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame centerCustom:(BOOL)centerCustom config:(QXTabbarConfig *)config;
|
||||
|
||||
|
||||
- (void)addTabBarButtonNorImageUrl:(NSString *)norImageUrl
|
||||
selImageUrl:(NSString *)selImageUrl
|
||||
title:(NSString *)title;
|
||||
|
||||
|
||||
@property (nonatomic, weak) id<QXTabBarDelegate> delegate;
|
||||
@property (nonatomic,assign)UInt64 unReadNumber;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
186
QXLive/Tabbar/TabbarCustomView/QXTabBar.m
Normal file
186
QXLive/Tabbar/TabbarCustomView/QXTabBar.m
Normal file
@@ -0,0 +1,186 @@
|
||||
//
|
||||
// QXTabBar.m
|
||||
// FreeTabbar_JoeJin
|
||||
//
|
||||
// Created by J-Mac on 2024/5/24.
|
||||
// Copyright © 2024 JoeJin-QQ:853105953. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QXTabBar.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
#import "QXTabbarConfig.h"
|
||||
#import "QXTabBarButton.h"
|
||||
|
||||
@interface QXTabBar()<QXTabBarButtonDelegate>
|
||||
/// 当前选中的按钮
|
||||
@property (nonatomic, weak) QXTabBarButton *selectedButton;
|
||||
/// UITabBarItem对象数组
|
||||
@property(nonatomic, strong)NSMutableArray *tabbarBtnArray;
|
||||
/// norImage
|
||||
@property (nonatomic, strong) NSMutableArray *norImageArrM;
|
||||
/// SelImage
|
||||
@property (nonatomic, strong) NSMutableArray *selImageArrM;
|
||||
/// 背景图片
|
||||
@property (nonatomic, strong) UIImageView *bgImageView;
|
||||
@property (nonatomic, assign) BOOL centerCustom;
|
||||
|
||||
@property (nonatomic, weak) QXTabBarButton *messageBtn;
|
||||
@end
|
||||
|
||||
@implementation QXTabBar
|
||||
|
||||
- (NSMutableArray *)tabbarBtnArray {
|
||||
if (!_tabbarBtnArray) {
|
||||
_tabbarBtnArray = [NSMutableArray array];
|
||||
}
|
||||
return _tabbarBtnArray;
|
||||
}
|
||||
|
||||
- (NSMutableArray *)norImageArrM {
|
||||
if (!_norImageArrM) {
|
||||
_norImageArrM = [NSMutableArray array];
|
||||
}
|
||||
return _norImageArrM;
|
||||
}
|
||||
|
||||
- (NSMutableArray *)selImageArrM {
|
||||
if (!_selImageArrM) {
|
||||
_selImageArrM = [NSMutableArray array];
|
||||
}
|
||||
return _selImageArrM;
|
||||
}
|
||||
|
||||
- (UIImageView *)bgImageView {
|
||||
if (!_bgImageView) {
|
||||
_bgImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"tabbar背景"]];
|
||||
_bgImageView.userInteractionEnabled = YES;
|
||||
}
|
||||
return _bgImageView;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame centerCustom:(BOOL)centerCustom config:(QXTabbarConfig *)config{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
self.centerCustom = self.centerCustom;
|
||||
[self addSubview:self.bgImageView];
|
||||
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self).offset(0);//[[QXTabbarConfig shareInstance]bgImageOffset]
|
||||
make.left.right.equalTo(self);
|
||||
make.bottom.equalTo(self);
|
||||
}];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)addTabBarButtonNorImageUrl:(NSString *)norImageUrl
|
||||
selImageUrl:(NSString *)selImageUrl
|
||||
title:(NSString *)title {
|
||||
|
||||
// 1.创建按钮
|
||||
QXTabBarButton *tabBarBtn = [[QXTabBarButton alloc] init];
|
||||
tabBarBtn.delegate = self;
|
||||
[self addSubview:tabBarBtn];
|
||||
// 2.设置数据
|
||||
[tabBarBtn setTabBarImageUrl:norImageUrl selectedImg:selImageUrl title:title];
|
||||
// 3.监听按钮点击
|
||||
[tabBarBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchDown];
|
||||
// 4.将自定义的YBTabBarButton对象
|
||||
[self.tabbarBtnArray addObject:tabBarBtn];
|
||||
[self.norImageArrM addObject:norImageUrl];
|
||||
// 5.默认选中第0个按钮
|
||||
if (self.tabbarBtnArray.count == 1) {
|
||||
[self buttonClick:tabBarBtn];
|
||||
[tabBarBtn.iconBtn setSelected:YES];
|
||||
}
|
||||
|
||||
if ([title isEqualToString:QXText(@"消息")]) {
|
||||
self.messageBtn = tabBarBtn;
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setUnReadNumber:(UInt64)unReadNumber{
|
||||
_unReadNumber = unReadNumber;
|
||||
[self.messageBtn.unreadView setNum:unReadNumber];
|
||||
}
|
||||
|
||||
/// 当前点击的按钮置为选中样式
|
||||
#pragma mark - 设置选中的ybButton
|
||||
- (void)JJDealSelectButton:(QXTabBarButton *)ybButton {
|
||||
for (int i = 0; i < self.tabbarBtnArray.count; i++) {
|
||||
QXTabBarButton *currentButton = self.tabbarBtnArray[i];
|
||||
if (currentButton == ybButton) {
|
||||
[currentButton.iconBtn setSelected:YES];
|
||||
currentButton.titleLbl.textColor = QXConfig.themeColor;
|
||||
} else {
|
||||
[currentButton.iconBtn setSelected:NO];
|
||||
currentButton.titleLbl.textColor = [[QXTabbarConfig shareInstance] norTitleColor];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - <QXTabBarButtonDelegate>
|
||||
- (void)QXTabbarIconButtonClick:(QXTabBarButton *)button {
|
||||
[self buttonClick:button];
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听按钮点击
|
||||
*/
|
||||
- (void)buttonClick:(QXTabBarButton *)button {
|
||||
// 1.通知代理
|
||||
if ([self.delegate respondsToSelector:@selector(QXTabBar:didSelectedButtonFrom:to:)]) {
|
||||
[self.delegate QXTabBar:self didSelectedButtonFrom:self.selectedButton.tag to:button.tag];
|
||||
}
|
||||
if (![QXGlobal shareGlobal].isLogin && button.tag == QXConfig.tabbarArray.count-1) {
|
||||
return;
|
||||
}
|
||||
// 2.设置按钮的状态
|
||||
self.selectedButton.selected = NO;
|
||||
button.selected = YES;
|
||||
self.selectedButton = button;
|
||||
[self JJDealSelectButton:self.selectedButton];
|
||||
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
|
||||
// 按钮的frame数据
|
||||
CGFloat buttonH = self.frame.size.height;
|
||||
CGFloat buttonW = self.frame.size.width / self.tabbarBtnArray.count;
|
||||
CGFloat buttonY = 0;
|
||||
for (int index = 0; index<self.tabbarBtnArray.count; index++) {
|
||||
// 1.取出按钮
|
||||
QXTabBarButton *button = self.tabbarBtnArray[index];
|
||||
// 2.设置按钮的frame
|
||||
CGFloat buttonX = index * buttonW;
|
||||
|
||||
if(index==2 && self.centerCustom){
|
||||
[button.titleLbl mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self);
|
||||
make.top.equalTo(button.iconBtn.mas_bottom).offset([[QXTabbarConfig shareInstance] titleOffset]);
|
||||
make.left.right.equalTo(self);
|
||||
make.height.mas_equalTo([[QXTabbarConfig shareInstance]titleHeight]);
|
||||
}];
|
||||
button.frame = CGRectMake(buttonX, -18, buttonW, buttonH);
|
||||
[button.iconBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(button.mas_centerX);
|
||||
make.top.equalTo(button.mas_top);
|
||||
make.height.width.mas_equalTo(65);
|
||||
}];
|
||||
}else{
|
||||
|
||||
button.frame = CGRectMake(buttonX, buttonY, buttonW, buttonH);
|
||||
}
|
||||
|
||||
// 3.绑定tag
|
||||
button.tag = index;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
40
QXLive/Tabbar/TabbarCustomView/QXTabBarButton.h
Normal file
40
QXLive/Tabbar/TabbarCustomView/QXTabBarButton.h
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// QXTabBarButton.h
|
||||
// FreeTabbar_JoeJin
|
||||
//
|
||||
// Created by J-Mac on 2024/5/24.
|
||||
// Copyright © 2024 JoeJin-QQ:853105953. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <Masonry/Masonry.h>
|
||||
#import "QXTabbarConfig.h"
|
||||
#import "TIMCommonModel.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class QXTabBarButton;
|
||||
|
||||
@protocol QXTabBarButtonDelegate <NSObject>
|
||||
|
||||
- (void)QXTabbarIconButtonClick:(QXTabBarButton *)button;
|
||||
|
||||
@end
|
||||
|
||||
@interface QXTabBarButton : UIControl
|
||||
@property (nonatomic, weak) id<QXTabBarButtonDelegate> delegate;
|
||||
|
||||
/// 背景图片按钮
|
||||
@property (nonatomic, strong) UIButton *iconBtn;
|
||||
/// 文字
|
||||
@property (nonatomic, strong) UILabel *titleLbl;
|
||||
|
||||
@property (nonatomic,strong)TUIUnReadView *unreadView;
|
||||
/// 设置自定义tabbar的图片和文字
|
||||
/// @param imageUrl 图片URL路径
|
||||
/// @param title 标题文字
|
||||
- (void)setTabBarImageUrl:(NSString *)imageUrl selectedImg:(NSString*)imageName title:(NSString *)title;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
122
QXLive/Tabbar/TabbarCustomView/QXTabBarButton.m
Normal file
122
QXLive/Tabbar/TabbarCustomView/QXTabBarButton.m
Normal file
@@ -0,0 +1,122 @@
|
||||
//
|
||||
// QXTabBarButton.m
|
||||
// FreeTabbar_JoeJin
|
||||
//
|
||||
// Created by J-Mac on 2024/5/24.
|
||||
// Copyright © 2024 JoeJin-QQ:853105953. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QXTabBarButton.h"
|
||||
|
||||
@implementation QXTabBarButton
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self addSubviews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)addSubviews {
|
||||
|
||||
[self addSubview:self.iconBtn];
|
||||
[self addSubview:self.titleLbl];
|
||||
[self.iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self);
|
||||
make.top.equalTo(self.mas_top).offset(-1);
|
||||
make.height.width.mas_equalTo(32);
|
||||
}];
|
||||
|
||||
|
||||
[self.titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self);
|
||||
make.top.equalTo(self.iconBtn.mas_bottom).offset(0);
|
||||
make.left.right.equalTo(self);
|
||||
make.height.mas_equalTo(12);
|
||||
}];
|
||||
[self addTarget:self action:@selector(iconButtonClick:) forControlEvents:(UIControlEventTouchDown)];
|
||||
|
||||
self.unreadView = [[TUIUnReadView alloc] init];
|
||||
[self.unreadView setNum:0];
|
||||
[self addSubview:self.unreadView];
|
||||
[self.unreadView.unReadLabel sizeToFit];
|
||||
[self.unreadView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self);
|
||||
make.left.equalTo(self.iconBtn.mas_right).offset(-10);
|
||||
make.width.mas_equalTo(kScale375(20));
|
||||
make.height.mas_equalTo(kScale375(20));
|
||||
}];
|
||||
|
||||
|
||||
[self.unreadView.unReadLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.center.mas_equalTo(self.unreadView);
|
||||
make.size.mas_equalTo(self.unreadView.unReadLabel);
|
||||
}];
|
||||
self.unreadView.layer.cornerRadius = kScale375(10);
|
||||
[self.unreadView.layer masksToBounds];
|
||||
}
|
||||
|
||||
#pragma mark -- 点击
|
||||
- (void)iconButtonClick:(QXTabBarButton *)ybButton {
|
||||
// if (ybButton.titleLbl.text.length == 0) {
|
||||
[self heartAnimationWithView:ybButton.iconBtn];
|
||||
// }
|
||||
if ([self.delegate respondsToSelector:@selector(QXTabbarIconButtonClick:)]) {
|
||||
[self.delegate QXTabbarIconButtonClick:self];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -- lazy load
|
||||
|
||||
- (UIButton *)iconBtn {
|
||||
if (!_iconBtn) {
|
||||
_iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
//_iconBtn.backgroundColor = [UIColor cyanColor];
|
||||
_iconBtn.contentMode = UIViewContentModeScaleAspectFill;
|
||||
_iconBtn.userInteractionEnabled = NO;
|
||||
}
|
||||
return _iconBtn;
|
||||
}
|
||||
|
||||
- (UILabel *)titleLbl {
|
||||
if (!_titleLbl) {
|
||||
_titleLbl = [[UILabel alloc] init];
|
||||
_titleLbl.font = [UIFont systemFontOfSize:[[QXTabbarConfig shareInstance] titleFont]];
|
||||
//_titleLbl.textColor = KColorFromRGB(0x916d55);
|
||||
_titleLbl.textColor = [[QXTabbarConfig shareInstance] norTitleColor];
|
||||
_titleLbl.textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
return _titleLbl;
|
||||
}
|
||||
|
||||
/// 设置自定义tabbar的图片和文字
|
||||
/// @param title 标题文字
|
||||
- (void)setTabBarImageUrl:(NSString *)imageUrl selectedImg:(nonnull NSString *)imageName title:(nonnull NSString *)title {
|
||||
self.titleLbl.text = title;
|
||||
if ([imageUrl hasPrefix:@"http"] || [imageUrl hasPrefix:@"https"]) {
|
||||
[self.iconBtn sd_setBackgroundImageWithURL:[NSURL URLWithString:imageUrl] forState:UIControlStateNormal placeholderImage:nil];
|
||||
}else{
|
||||
[self.iconBtn setBackgroundImage:[UIImage imageNamed:imageUrl] forState:UIControlStateNormal];
|
||||
}
|
||||
if ([imageName hasPrefix:@"http"] || [imageName hasPrefix:@"https"]) {
|
||||
[self.iconBtn sd_setBackgroundImageWithURL:[NSURL URLWithString:imageName] forState:UIControlStateSelected placeholderImage:nil];
|
||||
}else{
|
||||
[self.iconBtn setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateSelected];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)heartAnimationWithView:(UIView*)view{
|
||||
CABasicAnimation *anima = [CABasicAnimation animation];
|
||||
anima.keyPath = @"transform.scale";
|
||||
anima.fromValue = @1.2;
|
||||
anima.toValue = @0.5;
|
||||
anima.repeatCount = 1;
|
||||
anima.duration = 0.1;
|
||||
anima.autoreverses = YES;
|
||||
anima.removedOnCompletion = YES;
|
||||
[view.layer addAnimation:anima forKey:nil];
|
||||
}
|
||||
@end
|
||||
44
QXLive/Tabbar/TabbarCustomView/QXTabbarConfig.h
Normal file
44
QXLive/Tabbar/TabbarCustomView/QXTabbarConfig.h
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// QXTabbarConfig.h
|
||||
// FreeTabbar_JoeJin
|
||||
//
|
||||
// Created by J-Mac on 2024/5/24.
|
||||
// Copyright © 2024 JoeJin-QQ:853105953. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Masonry/Masonry.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface QXTabbarConfig : NSObject
|
||||
|
||||
/**
|
||||
单例模式
|
||||
*/
|
||||
+ (instancetype)shareInstance;
|
||||
|
||||
/**
|
||||
* 默认配置/恢复默认配置(有需调用)
|
||||
*/
|
||||
- (void)configNormal;
|
||||
|
||||
/** 标题的默认颜色 (默认为 #808080) */
|
||||
@property (nonatomic, strong) UIColor *norTitleColor;
|
||||
/** 标题的选中颜色 (默认为 #d81e06)*/
|
||||
@property (nonatomic, strong) UIColor *selTitleColor;
|
||||
/** 图片的size (默认 50*50) */
|
||||
@property (nonatomic, assign) CGSize imageSize;
|
||||
/** 标签的高度 (默认 12) */
|
||||
@property (nonatomic, assign) CGFloat titleHeight;
|
||||
/** 标题文字大小 (默认 12.f) */
|
||||
@property (nonatomic, assign) CGFloat titleFont;
|
||||
/** 标题的偏移值 (标题距离底部的距离 默认 5.f) */
|
||||
@property (nonatomic, assign) CGFloat titleOffset;
|
||||
/** 图片的偏移值 (图片距离顶部的距离 默认 5.f) */
|
||||
@property (nonatomic, assign) CGFloat imageOffset;
|
||||
/** 背景图片的偏移值 (图片距离顶部的距离 默认 20.f) */
|
||||
@property (nonatomic, assign) CGFloat bgImageOffset;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
46
QXLive/Tabbar/TabbarCustomView/QXTabbarConfig.m
Normal file
46
QXLive/Tabbar/TabbarCustomView/QXTabbarConfig.m
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// QXTabbarConfig.m
|
||||
// FreeTabbar_JoeJin
|
||||
//
|
||||
// Created by J-Mac on 2024/5/24.
|
||||
// Copyright © 2024 JoeJin-QQ:853105953. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QXTabbarConfig.h"
|
||||
|
||||
@implementation QXTabbarConfig
|
||||
|
||||
static id _instance = nil;
|
||||
|
||||
+ (instancetype)shareInstance {
|
||||
return [[self alloc] init];
|
||||
}
|
||||
|
||||
+ (instancetype)allocWithZone:(struct _NSZone *)zone {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_instance = [super allocWithZone:zone];
|
||||
});
|
||||
return _instance;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_instance = [super init];
|
||||
[self configNormal];
|
||||
});
|
||||
return _instance;
|
||||
}
|
||||
|
||||
- (void)configNormal {
|
||||
_norTitleColor = RGB16(0x999999);//[UIColor colorWithHexString:@"#808080"];
|
||||
_selTitleColor = RGB16(0x333333);//[UIColor colorWithHexString:@"#d81e06"];
|
||||
_imageSize = CGSizeMake(24, 24);
|
||||
_titleFont = 12.f;
|
||||
_titleOffset = 5.f;
|
||||
_imageOffset = 5.f;
|
||||
_titleHeight = 12.f;
|
||||
_bgImageOffset = 20.f;
|
||||
}
|
||||
@end
|
||||
Reference in New Issue
Block a user