-
Notifications
You must be signed in to change notification settings - Fork 9
/
SFSMenuCell.m
70 lines (53 loc) · 1.9 KB
/
SFSMenuCell.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
//
// SFSMenuCell.m
// SFSCollectionMenu
//
// Created by BJ Miller on 9/7/13.
// Copyright (c) 2013 Six Five Software, LLC. All rights reserved.
//
#import "SFSMenuCell.h"
#import <QuartzCore/QuartzCore.h>
@implementation SFSMenuCell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.contentView.layer.cornerRadius = 35.0f;
self.contentView.layer.borderWidth = 0.0f;
self.contentView.layer.borderColor = [UIColor whiteColor].CGColor;
self.contentView.backgroundColor = [UIColor darkGrayColor];
[self setAlpha:1.0];
self.backgroundImageView = [[UIImageView alloc] initWithFrame:self.bounds];
self.imageView = [[UIImageView alloc] initWithFrame:self.bounds];
[self addSubview:self.backgroundImageView];
[self.contentView addSubview:self.imageView];
}
return self;
}
- (BOOL)isAccessibilityElement {
return YES;
}
- (UIAccessibilityTraits)accessibilityTraits {
return UIAccessibilityTraitButton;
}
- (void)prepareForReuse {
[super prepareForReuse];
self.backgroundImageView.image = nil;
self.imageView.image = nil;
[self.imageView setFrame:self.bounds];
}
- (void)setBackgroundColorForCell:(UIColor *)color {
self.contentView.backgroundColor = color;
}
- (void)setBackgroundImageForCell:(UIImage *)image {
[self.backgroundImageView setImage:image];
}
- (void)setImageForCell:(UIImage *)image {
CGPoint center = CGPointMake(self.imageView.frame.size.width / 2.0, self.imageView.frame.size.height / 2.0);
CGFloat halfWidth = image.size.width / 2.0;
CGFloat halfHeight = image.size.height / 2.0;
CGPoint newOrigin = CGPointMake(center.x - halfWidth, center.y - halfHeight);
[self.imageView setFrame:CGRectMake(newOrigin.x, newOrigin.y, image.size.width, image.size.height)];
[self.imageView setImage:image];
}
@end