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
//
// ICRFunctionItemControl.m
// XFFruit
//
// Created by Lili Wang on 15/4/1.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#define ICRFUNCTION_IMG_TOP_PADDING (25)
#define ICRFUNCTION_IMG_WIDTH (65)
#define ICRFUNCTION_LABEL_HEIGHT (15)
#define ICRFUNCTION_INNER_GAP (7)
#define RIGHT_LINE_WIDTH (0.5)
#import "ICRFunctionItemControl.h"
@interface ICRFunctionItemControl ()
@property(strong, nonatomic) UIImageView *m_rightLine;
@property(strong, nonatomic) UIImageView *m_bottomLine;
@end
@implementation ICRFunctionItemControl
#pragma mark - life Cycle
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self _init];
}
return self;
}
- (void)layoutSubviews {
_functionImage.frame = (CGRect){
.origin.x = (CGRectGetWidth(self.frame) - ICRFUNCTION_IMG_WIDTH)/2,
.origin.y = ICRFUNCTION_IMG_TOP_PADDING,
.size.width = ICRFUNCTION_IMG_WIDTH,
.size.height = ICRFUNCTION_IMG_WIDTH
};
CGSize labelSize = CGSizeMake(CGRectGetWidth(self.frame), ICRFUNCTION_LABEL_HEIGHT);
labelSize = [_functinNameLabel sizeThatFits:labelSize];
_functinNameLabel.frame = (CGRect){
.origin.x = (CGRectGetWidth(self.frame) - labelSize.width)/2,
.origin.y = CGRectGetMaxY(_functionImage.frame) + ICRFUNCTION_INNER_GAP,
.size.width = labelSize.width,
.size.height = ICRFUNCTION_LABEL_HEIGHT
};
_m_rightLine.frame = (CGRect){
.origin.x = CGRectGetWidth(self.frame) - RIGHT_LINE_WIDTH,
.origin.y = 0,
.size.width = RIGHT_LINE_WIDTH,
.size.height = CGRectGetHeight(self.frame)
};
_m_bottomLine.frame = (CGRect){
.origin.x = 0,
.origin.y = CGRectGetHeight(self.frame) - RIGHT_LINE_WIDTH,
.size.width = CGRectGetWidth(self.frame),
.size.height = RIGHT_LINE_WIDTH
};
}
- (void)setHighlighted:(BOOL)highlighted{
[super setHighlighted:highlighted];
if (_highLightWhenTapped) {
self.alpha = highlighted ? IBT_BIN_HIGHLIGHT_ALPHA : 1.0f;
}
}
#pragma mark - Public Method
+ (ICRFunctionItemControl *)highLightControl {
ICRFunctionItemControl *control = [[ICRFunctionItemControl alloc] init];
control.highLightWhenTapped = YES;
return control;
}
#pragma mark - Private Method
- (void)_init {
self.functionImage = [[UIImageView alloc] init];
_functionImage.layer.masksToBounds = YES;
_functionImage.layer.cornerRadius = 65 * 0.5;
_functionImage.backgroundColor = [UIColor clearColor];
[self addSubview:_functionImage];
self.functinNameLabel = [[UILabel alloc] init];
_functinNameLabel.textColor = [UIColor colorWithRed:0.596f green:0.596f blue:0.596f alpha:1.00f];
_functinNameLabel.textAlignment = NSTextAlignmentCenter;
_functinNameLabel.font = [UIFont systemFontOfSize:13];
[self addSubview:_functinNameLabel];
self.m_rightLine = [[UIImageView alloc] init];
_m_rightLine.backgroundColor = [UIColor colorWithRed:0.596f green:0.596f blue:0.596f alpha:1.00f];
[self addSubview:_m_rightLine];
self.m_bottomLine = [[UIImageView alloc] init];
_m_bottomLine.backgroundColor = [UIColor colorWithRed:0.596f green:0.596f blue:0.596f alpha:1.00f];
[self addSubview:_m_bottomLine];
}
@end