-
Notifications
You must be signed in to change notification settings - Fork 8
/
SDCollectionViewCell.m
executable file
·96 lines (75 loc) · 2.28 KB
/
SDCollectionViewCell.m
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
//
// SDCollectionViewCell.m
// SDCycleScrollView
//
// Created by aier on 15-3-22.
// Copyright (c) 2015年 GSD. All rights reserved.
//
/**
*******************************************************
* *
* 感谢您的支持, 如果下载的代码在使用过程中出现BUG或者其他问题 *
* 您可以发邮件到[email protected] 或者 到 *
* https://github.com/gsdios?tab=repositories 提交问题 *
* *
*******************************************************
*/
#import "SDCollectionViewCell.h"
#import "UIView+SDExtension.h"
@implementation SDCollectionViewCell
{
__weak UILabel *_titleLabel;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self setupImageView];
[self setupTitleLabel];
}
return self;
}
- (void)setTitleLabelBackgroundColor:(UIColor *)titleLabelBackgroundColor
{
_titleLabelBackgroundColor = titleLabelBackgroundColor;
_titleLabel.backgroundColor = titleLabelBackgroundColor;
}
- (void)setTitleLabelTextColor:(UIColor *)titleLabelTextColor
{
_titleLabelTextColor = titleLabelTextColor;
_titleLabel.textColor = titleLabelTextColor;
}
- (void)setTitleLabelTextFont:(UIFont *)titleLabelTextFont
{
_titleLabelTextFont = titleLabelTextFont;
_titleLabel.font = titleLabelTextFont;
}
- (void)setupImageView
{
UIImageView *imageView = [[UIImageView alloc] init];
_imageView = imageView;
[self addSubview:imageView];
}
- (void)setupTitleLabel
{
UILabel *titleLabel = [[UILabel alloc] init];
_titleLabel = titleLabel;
_titleLabel.hidden = YES;
[self addSubview:titleLabel];
}
- (void)setTitle:(NSString *)title
{
_title = [title copy];
_titleLabel.text = [NSString stringWithFormat:@" %@", title];
}
- (void)layoutSubviews
{
[super layoutSubviews];
_imageView.frame = self.bounds;
CGFloat titleLabelW = self.sd_width;
CGFloat titleLabelH = _titleLabelHeight;
CGFloat titleLabelX = 0;
CGFloat titleLabelY = self.sd_height - titleLabelH;
_titleLabel.frame = CGRectMake(titleLabelX, titleLabelY, titleLabelW, titleLabelH);
_titleLabel.hidden = !_titleLabel.text;
}
@end