-
Notifications
You must be signed in to change notification settings - Fork 0
/
JWCategoryView.m
executable file
·85 lines (56 loc) · 1.95 KB
/
JWCategoryView.m
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
//
// JWCategoryView.m
// ShopHugBackStageManage
//
// Created by apple on 2017/8/24.
// Copyright © 2017年 fenger. All rights reserved.
//
#import "JWCategoryView.h"
@implementation JWCategoryView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
-(instancetype)initWithTitle:(NSString *)titles ImageName:(NSString *)imageName TitleWidth:(CGFloat)width{
self = [super init];
if (self) {
self.backgroundColor = [UIColor whiteColor];
self.layer.masksToBounds = YES;
self.layer.cornerRadius = 5;
self.layer.borderColor = [UIColor lightGrayColor].CGColor;
self.layer.borderWidth = 1.0;
[self setupUIWithTitle:titles ImageName:imageName TitleWidth:width];
}
return self;
}
-(void)setupUIWithTitle:(NSString *)titles ImageName:(NSString *)imageName TitleWidth:(CGFloat)width{
self.imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imageName]];
self.name = [[UILabel alloc]init];
[self.name LabelSetupWithTextColor:[UIColor blackColor] Font:[UIFont systemFontOfSize:12] Title:titles TextAlignment:NSTextAlignmentCenter];
[self sd_addSubviews:@[_imgV,_name]];
_name.sd_layout
.centerYEqualToView(self)
//.leftSpaceToView(self, 5)
//.rightSpaceToView(self, 5)
.centerXEqualToView(self)
.heightIs(21)
.widthIs(width);
_imgV.sd_layout
.centerYEqualToView(self)
//.rightSpaceToView(self, 5)
.leftSpaceToView(_name, 0)
.heightIs(11)
.widthIs(11);
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
[self addGestureRecognizer:tap];
}
#pragma mark - 手势
-(void)tap{
if (self.tapBlock) {
self.tapBlock();
}
}
@end