LVCTabBar.m 1.78 KB

//
//  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)/ 4;
    CGFloat buttonH = 30;
    
    NSInteger index = 0;
    for (UIView *subView in self.subviews) {
        if(subView.class != NSClassFromString(@"UITabBarButton"))continue;
        
        CGFloat buttonX = index * buttonW;
        if (index >= 2)
        {
            buttonX += 195 / 3;
        }
        
        subView.frame = CGRectMake(buttonX, buttonY, buttonW, buttonH);
        // 增加索引
        index++;
    }
}

//直播按钮点击事件
- (void)liveBtnClick
{
    if([self.LVCTabBarDelegate respondsToSelector:@selector(liveBtnClick:)])
    {
        [self.LVCTabBarDelegate liveBtnClick:self];
    }
}
@end