There are a few methods in the NSBezierPath class called "appendBezierPathWithRoundedRect....".
I havent tried them out myself, but they might work. It's worth a try.
There are a few methods in the NSBezierPath class called "appendBezierPathWithRoundedRect....".
I havent tried them out myself, but they might work. It's worth a try.
There is also another type of badge that you might already know, it's the "red" one that is on the application icon. They are created by doing something like:
NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
NSString *caldate = [[now
dateWithCalendarFormat:@"%b"
timeZone:nil] description];
[self setApplicationBadge:caldate];"
this will set the badge with a 3 letter abbreviation for the current month.
To my knowledge there's no API for this. However, using CoreGraphics (NSBezierPath is not available on iPhone), you can do it pretty easily. It's just two arcs in a CGPath and some text:
CGContextRef context = UIGraphicsGetCurrentContext();
float radius = bounds.size.height / 2.0;
NSString *countString = [NSString stringWithFormat: @"%d", count];
CGContextClearRect(context, bounds);
CGContextSetFillColorWithColor(context, ovalColor);
CGContextBeginPath(context);
CGContextAddArc(context, radius, radius, radius, M_PI / 2 , 3 * M_PI / 2, NO);
CGContextAddArc(context, bounds.size.width - radius, radius, radius, 3 * M_PI / 2, M_PI / 2, NO);
CGContextClosePath(context);
CGContextFillPath(context);
[[UIColor whiteColor] set];
UIFont *font = [UIFont boldSystemFontOfSize: 14];
CGSize numberSize = [countString sizeWithFont: font];
bounds.origin.x = (bounds.size.width - numberSize.width) / 2;
[countString drawInRect: bounds withFont: font];
I think a better way to implement something very close to the UITabBarItem
badge is to use the UIImage stretchableImageWithLeftCapWidth:topCapHeight:
method where both end caps could be a fancier image and the middle will be strech automatically (using the 1px wide image) to fit the NSString
size that would be overlaid on top.
Still need to get the proper images but that could be easily pulled from a screenshot or constructed from PS.