LVCTabBar.m
1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// LVCTabBar.m
// LiveVideoCloud
//
// Created by 张旭 on 2017/3/7.
// Copyright © 2017年 cnlive. All rights reserved.
//
#import "LVCTabBar.h"
#import "UIView+Extension.h"
@interface LVCTabBar()
@property (nonatomic ,strong)UIButton *liveBtn;
@end
@implementation LVCTabBar
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
// self.backgroundImage = [UIImage imageNamed:@""];
}
return self;
}
- (UIButton *)liveBtn
{
if (!_liveBtn) {
_liveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_liveBtn setImage:[UIImage imageNamed:@"Begin to live"] forState:UIControlStateNormal];
[_liveBtn addTarget:self action:@selector(liveBtnClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_liveBtn];
}
return _liveBtn;
}
- (void)layoutSubviews
{
[super layoutSubviews];
self.liveBtn.top = self.height - 195 / 3;
_liveBtn.left = SCREEN_WIDTH * 0.5 - 195 / 6;
_liveBtn.width = 195 / 3;
_liveBtn.height = 195 / 3;
CGFloat buttonY = 19 - 3;//19 - 3.5;
CGFloat buttonW = (self.width - 195 / 3)/ 2;
CGFloat buttonH = 30;
NSInteger index = 0;
for (UIView *subView in self.subviews) {
if(subView.class != NSClassFromString(@"UITabBarButton"))continue;
CGFloat buttonX = index * buttonW;
if (index >= 1)
{
buttonX += 195 / 3;
}
subView.frame = CGRectMake(buttonX, buttonY, buttonW, buttonH);
// 增加索引
index++;
}
}
//直播按钮点击事件
- (void)liveBtnClick
{
if([self.LVCTabBarDelegate respondsToSelector:@selector(liveBtnClick:)])
{
[self.LVCTabBarDelegate liveBtnClick:self];
}
}
@end