據我所知,這沒有API。但是,使用CoreGraphics(NSBezierPath在iPhone上不可用),你可以很容易地做到這一點。這是在CGPath只有兩個弧和一些文字:
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];
謝謝本。這正是我需要的。 – leonho 2008-11-04 05:11:21