Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rounded corners of MKMapView

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

like image 300
Kaspa Avatar asked Aug 29 '09 12:08

Kaspa


People also ask

What is a rounded corner called?

In construction terminology, a rounded corner is called a "bullnose corner." Sheetrock corners, tiles, countertop edges, and moldings may all have this feature.


1 Answers

The easiest way to make round corners:

#import <QuartzCore/QuartzCore.h>
myMapView.layer.cornerRadius = 10.0;
like image 138
digdog Avatar answered Sep 21 '22 08:09

digdog