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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//
// Toolview.m
// Lighting
//
// Created by 曹云霄 on 16/4/27.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "Toolview.h"
#import "CustomButton.h"
#import "UserViewController.h"
#define ButtonWIDTH 80 //按钮宽度
#define Buttoninterval 20//按钮间隔
#define ButtonRIGHT 54//按钮高度
@implementation Toolview
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = kTCColor(255, 255, 255);
[self uiConfigAction];
[self addNSNotificationCenter];
}
return self;
}
#pragma mark -布局
- (void)uiConfigAction
{
//阴影
self.layer.shadowColor = [UIColor blackColor].CGColor;
self.layer.shadowRadius = 10;
self.layer.shadowOpacity = 0.5;
//图标
UIImageView *iconImage = [[UIImageView alloc]initWithFrame:CGRectMake(50, 13, 115, 35)];
iconImage.image = TCImage(@"欧");
[self addSubview:iconImage];
//输入框背景
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];
//搜索图标
UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(10, 7.5, 20, 20)];
imageview.image = TCImage(@"search");
[backView addSubview:imageview];
//输入框
self.inputField = [[UITextField alloc]initWithFrame:CGRectMake(45, 0, 170, 35)];
self.inputField.borderStyle = UITextBorderStyleNone;
self.inputField.placeholder = @"请输入关键字";
self.inputField.font = [UIFont systemFontOfSize:12];
self.inputField.returnKeyType = UIReturnKeySearch;
[backView addSubview:self.inputField];
//扫描二维码
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];
//按钮
NSString *realName = [[Shoppersmanager manager].Shoppers.employee.realName length]?[Shoppersmanager manager].Shoppers.employee.realName:@"服务导购";
NSArray *titleArray = [NSArray arrayWithObjects:@"功能菜单",@"公告",realName,@"我的客户",@"购物袋", nil];
//图片
NSArray *imageArray = [NSArray arrayWithObjects:@"dial",@"tips",@"矢量智能对象-1",@"data",@"ablum", nil];
for (int i=1; i<titleArray.count+1; i++) {
CustomButton *button = [CustomButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(ScreenWidth-(i*ButtonWIDTH + Buttoninterval*(i-1)), 10, ButtonWIDTH, ButtonRIGHT);
[button setTitleColor:kMainBlueColor 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 setImage:TCImage([imageArray objectAtIndex_opple:i-1]) forState:UIControlStateNormal];
[self addSubview:button];
if (i == titleArray.count) {
SHARED_APPDELEGATE.shoppingCarPoint = [self convertPoint:CGPointMake(button.center.x, button.center.y) toView:self.window];
}
}
//创建下划线
CustomButton *Newbutton = (CustomButton *)[self viewWithTag:102];
self.underlineView = [[UIView alloc]initWithFrame:CGRectMake(Newbutton.frame.origin.x+(ButtonWIDTH-50)/2, ButtonRIGHT+8, 50, 2)];
SHARED_APPDELEGATE.lineView = self.underlineView;
_underlineView.backgroundColor = kMainBlueColor;
[self addSubview:self.underlineView];
}
#pragma mark - 监听通知
- (void)addNSNotificationCenter
{
//刷新购物车数量
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshGoodsNumber:) name:REFRESHSHOPPINGCAR object:nil];
//重置购物车数量
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetGoodNumber:) name:ADDSHOPPINGCAR object:nil];
//更改用户名
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ChangeCustomerName:) name:CHANGECUSTOMERNAME object:nil];
//更改导购名
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ChangeShoppersName:) name:CHANGESHOPPERSNAME object:nil];
//提示抽奖信息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(promptDrawInformation:) name:PROMPTDRAWINFORMATION object:nil];
}
#pragma mark -刷新购物车显示数量
- (void)refreshGoodsNumber:(NSNotification *)object
{
CustomButton *button = (CustomButton *)[self viewWithTag:104];
NSInteger number = [object.object integerValue];
if (number) {
button.instructionsNumber += number;
}else {
button.instructionsNumber = 0;
}
}
#pragma mark - 重置购物车显示数量
- (void)resetGoodNumber:(NSNotification *)object
{
CustomButton *button = (CustomButton *)[self viewWithTag:104];
NSInteger number = [object.object integerValue];
button.instructionsNumber = number;
}
#pragma mark - 提示抽奖机会
- (void)promptDrawInformation:(NSNotification *)object
{
CustomButton *button = (CustomButton *)[self viewWithTag:102];
NSInteger number = [object.object integerValue];
if (number) {
button.instructionsNumber += number;
}else{
button.instructionsNumber = 0;
}
}
#pragma mark -更改当前用户名
- (void)ChangeCustomerName:(NSNotification *)object
{
UIButton *button = [self viewWithTag:103];
NSString *userName = object.object;
if ([BaseViewController isBlankString:userName]) {
userName = @"我的客户";
}
[button setTitle:userName forState:UIControlStateNormal];
}
#pragma mark -更改导购名字
- (void)ChangeShoppersName:(NSNotification *)object
{
UIButton *button = [self viewWithTag:102];
NSString *userName = object.object;
if ([BaseViewController isBlankString:userName]) {
userName = @"导购";
}
[button setTitle:userName forState:UIControlStateNormal];
}
#pragma mark -二维码扫描码
- (void)QrCodeButtonClickAction
{
if ([self.delegate respondsToSelector:@selector(QrcodeButtonClick)]) {
[self.delegate QrcodeButtonClick];
}
}
#pragma mark -按钮事件响应
- (void)ButtonClick:(UIButton *)button
{
if (button.tag == 101 || button.tag == 103 || button.tag == 104) {
if (!(button.tag == 104 && ![Shoppersmanager manager].currentCustomer)) {
self.underlineView.hidden = NO;
//下划线动画
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
CGRect frame = self.underlineView.frame;
frame.origin.x = button.frame.origin.x+(ButtonWIDTH-50)/2;
self.underlineView.frame = frame;
} completion:nil];
}
}
//点击代理
if ([self.delegate respondsToSelector:@selector(ButtonClickAction:withButton:)]) {
[self.delegate ButtonClickAction:button.tag withButton:button];
}
}
@end