I'm building a custom UITableView with each of the cells containing a piece of text and a MKMapView. I want the map "icon" view in the cell to have rounded corners and this seems to be an issue.
I'm using custom drawing both for my UITableViewCell and my MapIcon
(custom map view) that I add to my UITableViewCell.
MapIcon
is a subclass of MKMapView
and the drawing method looks as follows:
-(void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, strokeWidth); CGContextSetStrokeColorWithColor(context,self.strokeColor.CGColor); CGContextSetFillColorWithColor(context, self.rectColor.CGColor); CGFloat radius = arcRadius; CGFloat Xmin = CGRectGetMinX(rect); CGFloat Xmid = CGRectGetMidX(rect); CGFloat Xmax = CGRectGetMaxX(rect); CGFloat Ymin = CGRectGetMinY(rect); CGFloat Ymid = CGRectGetMidY(rect); CGFloat Ymax = CGRectGetMaxY(rect);
CGContextBeginPath(context); CGContextMoveToPoint(context, Xmin, Ymid); CGContextAddArcToPoint(context, Xmin, Ymin, Xmid, Ymin, radius); CGContextAddArcToPoint(context, Xmax, Ymin, Xmax, Ymid, radius); CGContextAddArcToPoint(context, Xmax, Ymax, Xmid, Ymax, radius); CGContextAddArcToPoint(context, Xmin, Ymax, Xmin, Ymid, radius); CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFillStroke);
CGContextClip(context); CGContextEndTransparencyLayer(context); }
And the maps do not get the corners rouned, as can be seen in the below screenshot:
alt text http://img190.imageshack.us/img190/948/picture1vmk.png
If however I change the MapIcon
to subclass from UIView and use the same custom drawing methods, the view gets clipped perfectly, image below:
alt text http://img503.imageshack.us/img503/6269/picture2xkq.png
Is it wrong for me to subclass MKMapView in such a way and expect it to clip? Any other any of rounding these corners?
Cheers, Kaspa
In construction terminology, a rounded corner is called a "bullnose corner." Sheetrock corners, tiles, countertop edges, and moldings may all have this feature.
The easiest way to make round corners:
#import <QuartzCore/QuartzCore.h>
myMapView.layer.cornerRadius = 10.0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With