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
//
// ICRAttachTitleView.m
// XFFruit
//
// Created by Xummer on 15/4/15.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "ICRAttachTitleView.h"
#define AT_VERTICAL_MARGIN (10.0f)
#define AT_HORIZON_MARGIN (10.0f)
@interface ICRAttachTitleView ()
@property (strong, nonatomic) UIImageView *m_icon;
@property (strong, nonatomic) IBTUILabel *m_titleLabel;
@end
@implementation ICRAttachTitleView
#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (!self) {
return nil;
}
[self initSubviews];
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGFloat fDy = AT_HORIZON_MARGIN;
CGFloat fW = self.width - 2 * fDy;
_m_icon.frame = (CGRect){
.origin.x = fDy,
.origin.y = 0,
.size.width = fW,
.size.height = fW
};
_m_titleLabel.frame = (CGRect){
.origin.x = 0,
.origin.y = _m_icon.bottom,
.size.width = self.width,
.size.height = 16
};
}
#pragma mark - Private Method
- (void)initSubviews {
self.backgroundColor = [UIColor clearColor];
self.m_icon = [[UIImageView alloc] init];
[self addSubview:_m_icon];
self.m_titleLabel = [[IBTUILabel alloc] init];
_m_titleLabel.textAlignment = NSTextAlignmentCenter;
_m_titleLabel.textColor = [UIColor lightGrayColor];
_m_titleLabel.font = [UIFont systemFontOfSize:12.0f];
[self addSubview:_m_titleLabel];
}
@end
@implementation ICRAttachTitleView (Configure)
- (void)updateWithTitle:(NSString *)title iconName:(NSString *)iconName {
self.m_titleLabel.text = title;
self.m_icon.image = [UIImage imageNamed:iconName];
}
@end