NewsVoiceTableViewCell.m
2.94 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
//
// NewsVoiceTableViewCell.m
// SCIOLiveCN
//
// Created by huayu on 16/12/9.
// Copyright © 2016年 huayu. All rights reserved.
//
#import "NewsVoiceTableViewCell.h"
@implementation NewsVoiceTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor clearColor];
_bgView = [[UIView alloc] init];
_bgView.backgroundColor = [UIColor whiteColor];
_bgView.layer.masksToBounds = YES;
_bgView.layer.cornerRadius = 6.0;
[self.contentView addSubview:_bgView];
_titleLabel=[[UILabel alloc]init];
[_titleLabel sizeToFit];
_titleLabel.numberOfLines = 0;
_titleLabel.textColor = HEXCOLOR(0x333333);
_titleLabel.font = [UIFont systemFontOfSize:16];
[_bgView addSubview:_titleLabel];
_timeLabel = [[UILabel alloc] init];
[_timeLabel sizeToFit];
_timeLabel.backgroundColor = [UIColor clearColor];
_timeLabel.textColor = HEXCOLOR(0x666666);
_timeLabel.font = [UIFont systemFontOfSize:12];
[_bgView addSubview:_timeLabel];
{
[_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@5);
make.left.equalTo(@12);
make.bottom.equalTo(@-5);
make.right.equalTo(@-12);
}];
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self->_bgView.mas_top).with.offset(10);
make.left.equalTo(self->_bgView.mas_left).with.offset(10);
make.right.equalTo(self->_bgView.mas_right).with.offset(-10);
}];
[_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self->_titleLabel.mas_bottom).with.offset(2);
make.left.mas_equalTo(self->_titleLabel);
make.bottom.mas_equalTo(self->_bgView.mas_bottom).with.offset(-10);
}];
}
}
return self;
}
- (void)reSetTagFrame {
CGRect frame = _tagLabel.frame;
[_tagLabel sizeToFit];
CGRect rect = [self calculateSizeWithFont:12 Text:_tagLabel.text];
frame.size.width = rect.size.width + 10;
frame.origin.x = MainScreenWidth - frame.size.width - 24 - 40 - 5;
[_tagLabel setFrame:frame];
}
-(CGRect)calculateSizeWithFont:(NSInteger)Font Text:(NSString *)Text{
NSDictionary *attr = @{NSFontAttributeName : [UIFont systemFontOfSize:Font]};
CGRect rect = [Text boundingRectWithSize:CGSizeMake(MAXFLOAT, 16)
options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin
attributes:attr
context:nil];
return rect;
}
@end