Toolview.m 3.16 KB
//
//  Toolview.m
//  Lighting
//
//  Created by 曹云霄 on 16/4/27.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "Toolview.h"
#import "CustomButton.h"

#define ButtonWIDTH 100 //按钮宽度
#define Buttoninterval 20//按钮间隔
#define ButtonRIGHT 54//按钮高度


@implementation Toolview

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


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
      
        self.backgroundColor = kTCColor(255, 255, 255);
        [self uiConfigAction];
    }
    return self;
}

#pragma mark -布局
- (void)uiConfigAction
{
    //阴影
    self.layer.shadowColor = [UIColor blackColor].CGColor;
    self.layer.shadowRadius = 6;
    self.layer.shadowOpacity = 0.8;
    
    //图标
    UIImageView *iconImage = [[UIImageView alloc]initWithFrame:CGRectMake(50, 10, 100, 45)];
    iconImage.image = TCImage(@"weibo");
    [self addSubview:iconImage];
    
    //输入框
    UITextField *inputField = [[UITextField alloc]initWithFrame:CGRectMake(200, (NavigationHeight-35)/2, 300, 35)];
    inputField.borderStyle = UITextBorderStyleNone;
    inputField.backgroundColor = [UIColor grayColor];
    inputField.placeholder = @"请输入关键字";
    [self addSubview:inputField];
    
    //按钮
    NSArray *titleArray = [NSArray arrayWithObjects:@"右视图",@"某某用户",@"我的客户",@"购物车", nil];
    for (int i=1; i<5; i++) {
        
        CustomButton *button = [CustomButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(ScreenWidth-(i*ButtonWIDTH + Buttoninterval*(i-1)), 10, ButtonWIDTH, ButtonRIGHT);
        [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [button setTitle:[titleArray objectAtIndex_opple:i-1] forState:UIControlStateNormal];
        button.tag = 100+i-1;
        [button addTarget:self action:@selector(ButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        button.instructionsNumber = i;
        if (i==1) {
            [button setImage:TCImage(@"business") forState:UIControlStateNormal];
        }else
        {
            [button setImage:TCImage(@"qq") forState:UIControlStateNormal];
        }
        
        [self addSubview:button];
        //创建下划线
        if (i == 3) {
            
            self.underlineView = [[UIView alloc]initWithFrame:CGRectMake(button.frame.origin.x+(ButtonWIDTH-50)/2, ButtonRIGHT+9, 50, 1)];
            _underlineView.backgroundColor = [UIColor redColor];
            [self addSubview:self.underlineView];
        }
    }
}


#pragma mark -按钮事件响应
- (void)ButtonClick:(UIButton *)button
{
    //下划线动画
    [UIView animateWithDuration:0.2 animations:^{
        
        self.underlineView.frame = CGRectMake(button.frame.origin.x+(ButtonWIDTH-50)/2, ButtonRIGHT+9, 50, 1);
        
    }];
    
    //点击代理
    if ([self.delegate respondsToSelector:@selector(ButtonClickAction:)]) {
        
      [self.delegate ButtonClickAction:button.tag];
    }
    
}




@end