LeftImageTableViewCell.m
3.36 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
//
// LeftImageTableViewCell.m
// SCIOLiveCN
//
// Created by huayu on 17/2/13.
// Copyright © 2017年 huayu. All rights reserved.
//
#import "LeftImageTableViewCell.h"
@implementation LeftImageTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor clearColor];
_backGroundView = [[UIView alloc] initWithFrame:CGRectMake(12, 6, MainScreenWidth - 24, 8 + MainScreenWidth*5/24)];
_backGroundView.backgroundColor = [UIColor whiteColor];
[self addSubview:_backGroundView];
_leftImage = [[UIImageView alloc] initWithFrame:CGRectMake(16, 10, MainScreenWidth/3, MainScreenWidth*5/24)];
_leftImage.contentMode = UIViewContentModeScaleAspectFill;
_leftImage.layer.masksToBounds = YES;
[self addSubview:_leftImage];
// _playImage = [[UIImageView alloc] initWithFrame:CGRectMake(16 + (MainScreenWidth/3 - 50)/2, 10 + (MainScreenWidth*5/24 - 25)/2, 25, 25)];
_playImage = [[UIImageView alloc] initWithFrame:CGRectMake((_leftImage.frame.size.width-25)/2, (_leftImage.frame.size.height-25)/2, 25, 25)];
[_leftImage addSubview:_playImage];
_titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(22 + MainScreenWidth/3, 6, MainScreenWidth - MainScreenWidth/3 - 38, MainScreenWidth*10/72)];
_titleLabel.numberOfLines = 2;
_titleLabel.textColor = HEXCOLOR(0x333333);
_titleLabel.font = [UIFont systemFontOfSize:16];
_titleLabel.backgroundColor = [UIColor clearColor];
[self addSubview:_titleLabel];
_timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(22 + MainScreenWidth/3, 6 + MainScreenWidth*5/24 - 16, MainScreenWidth - MainScreenWidth/3 - 38, 16)];
_timeLabel.textColor = HEXCOLOR(0x666666);
_timeLabel.font = [UIFont systemFontOfSize:12];
_timeLabel.backgroundColor = [UIColor clearColor];
[self addSubview:_timeLabel];
_tagsLabel = [[UILabel alloc] initWithFrame:CGRectMake(MainScreenWidth - 112, 6 + MainScreenWidth*5/24 - 16, 0, 16)];
_tagsLabel.textColor = HEXCOLOR(0xFFFFFF);
_tagsLabel.font = [UIFont systemFontOfSize:12];
_tagsLabel.textAlignment = NSTextAlignmentCenter;
_tagsLabel.backgroundColor = HEXCOLOR(0x195AC9);
_tagsLabel.layer.masksToBounds = YES;
_tagsLabel.layer.cornerRadius = 4.0;
[self addSubview:_tagsLabel];
}
return self;
}
- (void)reSetTagFrame {
CGRect frame = _tagsLabel.frame;
[_tagsLabel sizeToFit];
CGRect rect = [self calculateSizeWithFont:12 Text:_tagsLabel.text];
NSLog(@"%@",NSStringFromCGRect(rect));
frame.size.width = rect.size.width + 10;
frame.origin.x = MainScreenWidth - frame.size.width - 22;
[_tagsLabel 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