forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCategorySearchBar.m
More file actions
80 lines (68 loc) · 2.33 KB
/
CategorySearchBar.m
File metadata and controls
80 lines (68 loc) · 2.33 KB
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
//
// CategorySearchBar.m
// Coding_iOS
//
// Created by jwill on 15/11/18.
// Copyright © 2015年 Coding. All rights reserved.
//
#import "CategorySearchBar.h"
@interface CategorySearchBar ()
@property (copy,nonatomic)SelectBlock curBlock;
@property (strong, nonatomic)UIButton *categoryBtn;
@property (strong, nonatomic)UIButton *iconBtn;
@end
@implementation CategorySearchBar
-(void)layoutSubviews{
self.autoresizesSubviews = YES;
UITextField *searchField = self.eaTextField;
[searchField setFrame:CGRectMake(60, 4.5, self.frame.size.width - 75, 22)];
searchField.leftView = nil;
searchField.textAlignment = NSTextAlignmentLeft;
}
-(void)patchWithCategoryWithSelectBlock:(SelectBlock)block{
[self addSubview:self.categoryBtn];
[self addSubview:self.iconBtn];
_curBlock = block;
}
-(UIButton*)categoryBtn{
if (!_categoryBtn) {
_categoryBtn=[UIButton new];
_categoryBtn.frame=CGRectMake(5, 0, 40, 31);
[_categoryBtn addTarget:self action:@selector(selectCategoryAction) forControlEvents:UIControlEventTouchUpInside];
_categoryBtn.titleLabel.font = self.eaTextField.font;
[_categoryBtn setTitleColor:kColor666 forState:UIControlStateNormal];
[_categoryBtn setTitle:@"项目" forState:UIControlStateNormal];
}
return _categoryBtn;
}
-(UIButton*)iconBtn{
if (!_iconBtn) {
_iconBtn=[[UIButton alloc] initWithFrame:CGRectMake(45, 11, 8, 8)];
[_iconBtn addTarget:self action:@selector(selectCategoryAction) forControlEvents:UIControlEventTouchUpInside];
[_iconBtn setBackgroundImage:[UIImage imageNamed:@"btn_fliter_down"] forState:UIControlStateNormal];
}
return _iconBtn;
}
#pragma mark -- event
-(void)selectCategoryAction{
_curBlock();
}
-(void)setSearchCategory:(NSString*)title{
[_categoryBtn setTitle:title forState:UIControlStateNormal];
}
@end
@implementation MainSearchBar
- (UIButton *)scanBtn{
if (!_scanBtn) {
_scanBtn = [UIButton new];
[_scanBtn setImage:[UIImage imageNamed:@"button_scan"] forState:UIControlStateNormal];
[self addSubview:_scanBtn];
[_scanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(50, 30));
make.centerY.equalTo(self);
make.right.equalTo(self);
}];
}
return _scanBtn;
}
@end