//
//  CustomTabBar.m
//  gaotingshan
//
//  Created by MacBook Dq01 on 16/4/18.
//  Copyright © 2016年 Mac Book DQ02. All rights reserved.
//

#import "CustomTabBar.h"
#import "UIView+UIView_Extension.h"

#define kScreenWidth [UIScreen mainScreen].bounds.size.width


@interface CustomTabBar ()

@property (nonatomic, strong) UIButton *guideBtn;//电子导游按钮
@property (nonatomic, strong) UIButton *cultureBtn;//文创游按钮

@end

@implementation CustomTabBar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 添加一个+号按钮 到tabbar中
        UIButton *plusBtn = [[UIButton alloc] init];

       [plusBtn setBackgroundImage:[UIImage imageNamed:@"daoyou-80"] forState:UIControlStateNormal];
         plusBtn.size = plusBtn.currentBackgroundImage.size;
         [plusBtn setTitle:nil forState:(UIControlStateNormal)];
        [plusBtn addTarget:self action:@selector(guideBtnClicked) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:plusBtn];
        self.guideBtn = plusBtn;
        
    }
    return self;
}


/**
 *  电子导游按钮点击
 */
- (void)guideBtnClicked
{
    // 通知代理
    if ([self.clickDelegate respondsToSelector:@selector(tabBarDidClickguideButton:)]) {
        [self.clickDelegate tabBarDidClickguideButton:self];
    }
}


-(void)cultureBtnClicked
{
    // 通知代理
    if ([self.clickDelegate respondsToSelector:@selector(tabbarDidClickCultureButton:)]) {
        [self.clickDelegate tabbarDidClickCultureButton:self];
    }

}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 1.设置电子导游按钮的位置
    self.guideBtn.centerX = self.width*0.3;
    self.guideBtn.centerY = self.height * 0.5;
    
    // 2.设置其他tabbarButton的位置和尺寸
    CGFloat tabbarButtonW = self.width / 5.;
    CGFloat tabbarButtonIndex = 0;
    for (UIView *child in self.subviews) {
        Class class = NSClassFromString(@"UITabBarButton");
        if ([child isKindOfClass:class]) {
            // 设置宽度
            child.width = tabbarButtonW;
            // 设置x
            child.x = tabbarButtonIndex * tabbarButtonW;
            //设置y
            child.y = 0;
            // 增加索引
            tabbarButtonIndex++;
            if (tabbarButtonIndex == 1) {
                tabbarButtonIndex++;
            }
        }
    }
    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
