-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMenuCell.m
More file actions
73 lines (62 loc) · 1.88 KB
/
MenuCell.m
File metadata and controls
73 lines (62 loc) · 1.88 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
//
// MenuCell.m
// DuDu
//
// Created by i-chou on 11/17/15.
// Copyright © 2015 i-chou. All rights reserved.
//
#import "MenuCell.h"
@implementation MenuCell
{
UILabel *_titleLabel;
UIImageView *_bottomLine;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self createSubViews];
}
return self;
}
- (void)createSubViews
{
self.iconImage = [[UIImageView alloc]initWithFrame:CGRectZero];
self.iconImage.userInteractionEnabled = YES;
[self.contentView addSubview:self.iconImage];
_titleLabel = [UILabel labelWithFrame:CGRectZero
color:COLORRGB(0x000000)
font:HSFONT(15)
text:@""];
_titleLabel.textAlignment = NSTextAlignmentLeft;
[self.contentView addSubview:_titleLabel];
_bottomLine = [[UIImageView alloc] initWithFrame:CGRectZero];
_bottomLine.backgroundColor = COLORRGB(0xd7d7d7);
[self.contentView addSubview:_bottomLine];
}
- (void)setData
{
_titleLabel.text = self.title;
}
- (void)calculateFrame
{
[self setData];
self.iconImage.frame = ccr(20, (60-20)/2, 20, 20);
CGSize titleSize = [_titleLabel.text sizeWithAttributes:@{NSFontAttributeName:_titleLabel.font}];
[_titleLabel sizeToFit];
_titleLabel.frame = ccr(CGRectGetMaxX(_iconImage.frame)+5,
(60-titleSize.height)/2,
titleSize.width,
titleSize.height);
_bottomLine.frame = ccr(15, 60-0.5, SCREEN_WIDTH, 0.5);
}
- (void)layoutSubviews
{
[super layoutSubviews];
[self calculateFrame];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
}
@end