public
Description: Varies useful libs, classes, and methods for iPhone development
Homepage: http://www.stepcase.com
Clone URL: git://github.com/leonho/iphone-libs.git
iphone-libs / BlueBadge.m
100644 56 lines (41 sloc) 1.403 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
//
// BlueBadge.m
//
// Copyright 2008 Stepcase Limited.
//
 
#import "BlueBadge.h"
 
 
@implementation BlueBadge
 
@synthesize count;
 
- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
[self setBackgroundColor: [UIColor clearColor]];
[self setCount: 0];
    }
    return self;
}
 
 
- (void)drawRect:(CGRect)rect {
if (count == 0) return;
NSString *countString = [NSString stringWithFormat: @"%d", count];
UIFont *font = [UIFont boldSystemFontOfSize: 16];
CGSize numberSize = [countString sizeWithFont: font];
 
CGContextRef context = UIGraphicsGetCurrentContext();
float radius = numberSize.height / 2.0;
float startPoint = (rect.size.width - (numberSize.width + numberSize.height))/2.0;
 
CGContextSetRGBFillColor(context, 0.55, 0.6, 0.70, 1.0);
CGContextBeginPath(context);
CGContextAddArc(context, startPoint + radius, radius, radius, M_PI / 2 , 3 * M_PI / 2, NO);
CGContextAddArc(context, startPoint + radius + numberSize.width, radius, radius, 3 * M_PI / 2, M_PI / 2, NO);
CGContextClosePath(context);
CGContextFillPath(context);
 
[[UIColor whiteColor] set];
[countString drawInRect: CGRectMake(startPoint + radius, rect.origin.y, rect.size.width, rect.size.height) withFont: font];
}
 
- (void)drawWithCount:(NSInteger)i {
self.count = i;
[self setNeedsDisplay];
}
 
- (void)dealloc {
    [super dealloc];
}
 
 
@end