CNHomeRightHeaderFooterView.m
3.51 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// CNHomeRightHeaderFooterView.m
// CNLiveScioLive
//
// Created by Xiaowen Zhang on 2018/9/19.
// Copyright © 2018年 CNLive. All rights reserved.
//
#import "CNHomeRightHeaderFooterView.h"
@interface CNHomeRightHeaderFooterView()
@property (nonatomic, strong) UIImageView *backgroundImage;
@property (nonatomic, strong) UIImageView *picImage;
@property (nonatomic, strong) UILabel *titleLabel;
@end
@implementation CNHomeRightHeaderFooterView
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithReuseIdentifier:reuseIdentifier];
if (self) {
self.contentView.backgroundColor = [UIColor whiteColor];
_backgroundImage = [[UIImageView alloc] init];
_backgroundImage.contentMode = UIViewContentModeCenter;
_backgroundImage.layer.masksToBounds = YES;
_backgroundImage.userInteractionEnabled = YES;
_backgroundImage.backgroundColor = [UIColor whiteColor];
[self.contentView addSubview:_backgroundImage];
_titleLabel = [[UILabel alloc] init];
_titleLabel.numberOfLines = 1;
_titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
_titleLabel.textColor = HEXCOLOR(0x333333);
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.font = [UIFont systemFontOfSize:16];
[self.contentView addSubview:_titleLabel];
_picImage = [[UIImageView alloc] init];
_picImage.contentMode = UIViewContentModeCenter;
_picImage.layer.masksToBounds = YES;
_picImage.userInteractionEnabled = YES;
[self.contentView addSubview:_picImage];
}
return self;
}
- (void)setTitle:(NSString *)title{
_title = title;
_titleLabel.text = title;
if([title isEqualToString:@"搜索内容"]){
_picImage.image = [UIImage imageNamed:@"cnlive_search"];
}
else if([title isEqualToString:@"栏目列表"]){
_picImage.image = [UIImage imageNamed:@"cnlive_column"];
}
else{
_picImage.image = [UIImage imageNamed:@"cnlive_scan"];
}
}
- (void)layoutSubviews{
[_backgroundImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mas_top).with.offset(0);
make.bottom.equalTo(self.mas_bottom).with.offset(0);
make.left.equalTo(self.mas_left).with.offset(0);
make.right.equalTo(self.mas_right).with.offset(0);
}];
UIFont *font = [UIFont systemFontOfSize:16];
CGSize size = CGSizeMake(MAXFLOAT, 30.0f);
CGFloat titleWidth = [_title boundingRectWithSize:size options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{ NSFontAttributeName:font } context:nil].size.width;
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mas_left).with.offset((self.width-titleWidth)/2.0);
make.top.equalTo(self.mas_top).with.offset(0);
make.bottom.equalTo(self.mas_bottom).with.offset(0);
}];
[_picImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mas_top).with.offset(0);
make.bottom.equalTo(self.mas_bottom).with.offset(0);
make.right.equalTo(self->_titleLabel.mas_left).with.offset(-10);
make.width.offset(20);
}];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end