-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFUICellBackgroundView.m
executable file
·62 lines (47 loc) · 1.82 KB
/
FUICellBackgroundView.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
//
// UACellBackgroundView.m
// FlatUI
//
// Created by Maciej Swic on 2013-05-30.
// Licensed under the MIT license.
#import "FUICellBackgroundView.h"
@implementation FUICellBackgroundView
+ (void)initialize {
if (self == [FUICellBackgroundView class]) {
FUICellBackgroundView *appearance = [self appearance];
[appearance setCornerRadius:3.0f];
[appearance setSeparatorHeight:1.0f];
[appearance setSeparatorColor:[UIColor clearColor]];
}
}
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
self.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
}
return self;
}
- (BOOL)isOpaque {
return NO;
}
- (void)drawRect:(CGRect)aRect {
CGContextRef c = UIGraphicsGetCurrentContext();
int lineWidth = 1;
CGContextSetStrokeColorWithColor(c, [[UIColor grayColor] CGColor]);
CGContextSetLineWidth(c, lineWidth);
CGContextSetAllowsAntialiasing(c, YES);
CGContextSetShouldAntialias(c, YES);
CGSize radii = CGSizeMake(self.cornerRadius, self.cornerRadius);
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:self.roundedCorners
cornerRadii:radii];
CGPathRef path = bezierPath.CGPath;
CGContextSaveGState(c);
CGContextAddPath(c, path);
CGContextClip(c);
CGContextSetFillColorWithColor(c, self.backgroundColor.CGColor);
CGContextFillRect(c, self.bounds);
CGContextSetFillColorWithColor(c, self.separatorColor.CGColor);
CGContextFillRect(c, CGRectMake(0, self.bounds.size.height - self.separatorHeight, self.bounds.size.width, self.bounds.size.height - self.separatorHeight));
CGContextRestoreGState(c);
}
@end