-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBounceGalleryCell.m
97 lines (77 loc) · 2.19 KB
/
BounceGalleryCell.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
97
//
// BounceGalleryCell.m
//
// Created by Eli Gregory on 4/13/15.
// Copyright (c) 2015 Stublisher Inc. All rights reserved.
//
#import "BounceGalleryCell.h"
@interface BounceGalleryCell()
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIImageView *playButton;
@end
@implementation BounceGalleryCell
@synthesize imageView = _imageView;
@synthesize imgRef = _imgRef;
@synthesize playButton = _playButton;
const CGFloat playButtonSize = 36.0f;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
[self setBackgroundColor: [UIColor whiteColor]];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.bounds];
self.imageView = imageView;
self.imageView.contentMode = UIViewContentModeScaleToFill;
self.imageView.clipsToBounds = YES;
[self.imageView setBackgroundColor:[UIColor darkGrayColor]];
[self.contentView addSubview:self.imageView];
[self videoOverlay];
}
return self;
}
- (void)prepareForReuse
{
[super prepareForReuse];
[self.imageView setFrame:self.bounds];
[self videoOverlay];
}
-(void)videoOverlay
{
if (_imgRef.isVideo)
{
if (!_playButton)
{
_playButton = [[UIImageView alloc] init];
[_playButton setImage:[UIImage imageNamed:@"play"]];
[self.contentView addSubview:_playButton];
}
[_playButton setFrame:CGRectMake((_imgRef.size.width/2.0f)-(playButtonSize/2.0f),
(_imgRef.size.height/2.0f)-(playButtonSize/2.0f),
playButtonSize,
playButtonSize)];
}
else
{
if (_playButton)
{
[_playButton removeFromSuperview];
_playButton = nil;
}
}
}
-(void)setImgRef:(BounceGalleryImageRef *)imgRef
{
_imgRef = imgRef;
if (imgRef)
{
UIImage *thumb = [_imgRef galleryThumb];
if (thumb) [_imageView setImage:thumb];
}
else
{
[_imageView setImage:nil];
}
[self videoOverlay];
}
@end