Toolview.m 4.84 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10
//
//  Toolview.m
//  Lighting
//
//  Created by 曹云霄 on 16/4/27.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "Toolview.h"
#import "CustomButton.h"
曹云霄's avatar
曹云霄 committed
11
#import "UserViewController.h"
zhu's avatar
zhu committed
12

曹云霄's avatar
曹云霄 committed
13
#define ButtonWIDTH 80 //按钮宽度
zhu's avatar
zhu committed
14 15 16 17
#define Buttoninterval 20//按钮间隔
#define ButtonRIGHT 54//按钮高度


曹云霄's avatar
曹云霄 committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31
@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]) {
      
曹云霄's avatar
曹云霄 committed
32
        self.backgroundColor = kTCColor(255, 255, 255);
曹云霄's avatar
曹云霄 committed
33 34 35 36 37
        [self uiConfigAction];
    }
    return self;
}

曹云霄's avatar
曹云霄 committed
38 39


曹云霄's avatar
曹云霄 committed
40 41 42
#pragma mark -布局
- (void)uiConfigAction
{
曹云霄's avatar
曹云霄 committed
43 44
    //阴影
    self.layer.shadowColor = [UIColor blackColor].CGColor;
曹云霄's avatar
曹云霄 committed
45
    self.layer.shadowRadius = 4;
曹云霄's avatar
曹云霄 committed
46
    self.layer.shadowOpacity = 0.5;
曹云霄's avatar
曹云霄 committed
47 48
    self.layer.shadowOffset = CGSizeMake(0,0);

曹云霄's avatar
曹云霄 committed
49 50 51 52 53
    //图标
    UIImageView *iconImage = [[UIImageView alloc]initWithFrame:CGRectMake(50, 10, 100, 45)];
    iconImage.image = TCImage(@"weibo");
    [self addSubview:iconImage];
    
曹云霄's avatar
曹云霄 committed
54 55 56 57 58 59 60 61 62 63
    //输入框背景
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(200, (NavigationHeight-35)/2, 220, 35)];
    backView.backgroundColor = kTCColor(242, 242, 242);
    backView.layer.masksToBounds = YES;;
    backView.layer.cornerRadius = kCornerRadius;
    backView.layer.borderWidth = 1;
    backView.layer.borderColor = kTCColor(209, 209, 209).CGColor;
    [self addSubview:backView];

    //搜索图标
曹云霄's avatar
曹云霄 committed
64 65 66
    UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(10, 7.5, 20, 20)];
    imageview.image = TCImage(@"search");
    [backView addSubview:imageview];
曹云霄's avatar
曹云霄 committed
67 68
    
    
曹云霄's avatar
曹云霄 committed
69
    //输入框
曹云霄's avatar
曹云霄 committed
70
    UITextField *inputField = [[UITextField alloc]initWithFrame:CGRectMake(45, 0, 170, 35)];
曹云霄's avatar
曹云霄 committed
71 72
    inputField.borderStyle = UITextBorderStyleNone;
    inputField.placeholder = @"请输入关键字";
曹云霄's avatar
曹云霄 committed
73 74 75
    inputField.font = [UIFont systemFontOfSize:12];
    [backView addSubview:inputField];
    
曹云霄's avatar
曹云霄 committed
76
    
曹云霄's avatar
曹云霄 committed
77 78 79 80 81 82 83
    //扫描二维码
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(backView.frame.size.width+backView.frame.origin.x+15, (NavigationHeight-20)/2, 25, 20);
    [button setBackgroundImage:TCImage(@"圆角矩形-3") forState:UIControlStateNormal];
    [button addTarget:self action:@selector(QrCodeButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
    
曹云霄's avatar
曹云霄 committed
84

曹云霄's avatar
曹云霄 committed
85
    //按钮
zhu's avatar
zhu committed
86
    NSArray *titleArray = [NSArray arrayWithObjects:@"右视图",@"某某用户",@"我的客户",@"购物车", nil];
曹云霄's avatar
曹云霄 committed
87 88
    //图片
    NSArray *imageArray = [NSArray arrayWithObjects:@"dial",@"Cog",@"data",@"ablum", nil];
zhu's avatar
zhu committed
89
    for (int i=1; i<5; i++) {
曹云霄's avatar
曹云霄 committed
90 91 92
        
        CustomButton *button = [CustomButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(ScreenWidth-(i*ButtonWIDTH + Buttoninterval*(i-1)), 10, ButtonWIDTH, ButtonRIGHT);
曹云霄's avatar
曹云霄 committed
93
        [button setTitleColor:kMainBlueColor forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
94 95 96
        [button setTitle:[titleArray objectAtIndex_opple:i-1] forState:UIControlStateNormal];
        button.tag = 100+i-1;
        [button addTarget:self action:@selector(ButtonClick:) forControlEvents:UIControlEventTouchUpInside];
勾芒's avatar
勾芒 committed
97
  
曹云霄's avatar
曹云霄 committed
98
        [button setImage:TCImage([imageArray objectAtIndex_opple:i-1]) forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
99 100
        [self addSubview:button];
    }
曹云霄's avatar
曹云霄 committed
101 102 103 104 105 106
//    //创建下划线
//    CustomButton *button = (CustomButton *)[self viewWithTag:102];
//    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];
    
勾芒's avatar
勾芒 committed
107
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshGoodsNumber:) name:@"GOODSNUMBER" object:nil];
曹云霄's avatar
曹云霄 committed
108 109 110
}


勾芒's avatar
勾芒 committed
111 112 113 114 115 116 117 118
#pragma mark -刷新购物车显示数量
- (void)refreshGoodsNumber:(NSNotification *)objc
{
    CustomButton *button = (CustomButton *)[self viewWithTag:103];
    button.instructionsNumber = [objc.object integerValue];
    
}

曹云霄's avatar
曹云霄 committed
119 120 121 122 123 124 125 126 127
#pragma mark -二维码扫描码
- (void)QrCodeButtonClickAction
{
    if ([self.delegate respondsToSelector:@selector(QrcodeButtonClick)]) {
        
        [self.delegate QrcodeButtonClick];
    }
}

曹云霄's avatar
曹云霄 committed
128 129 130
#pragma mark -按钮事件响应
- (void)ButtonClick:(UIButton *)button
{
曹云霄's avatar
曹云霄 committed
131 132 133 134 135 136 137
//    //下划线动画
//    [UIView animateWithDuration:0.2 animations:^{
//        
//        CGRect frame = self.underlineView.frame;
//        frame.origin.x = button.frame.origin.x+(ButtonWIDTH-50)/2;
//        self.underlineView.frame = frame;
//    }];
曹云霄's avatar
曹云霄 committed
138
    
曹云霄's avatar
曹云霄 committed
139 140

    
曹云霄's avatar
曹云霄 committed
141
    //点击代理
曹云霄's avatar
曹云霄 committed
142
    if ([self.delegate respondsToSelector:@selector(ButtonClickAction:withButton:)]) {
曹云霄's avatar
曹云霄 committed
143
        
曹云霄's avatar
曹云霄 committed
144
        [self.delegate ButtonClickAction:button.tag withButton:button];
曹云霄's avatar
曹云霄 committed
145 146
    }
}
曹云霄's avatar
曹云霄 committed
147 148 149 150 151




@end