Note that there are some explanatory texts on larger screens.

plurals
  1. PORounded corners of MKMapView
    primarykey
    data
    text
    <p>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.</p> <p>I'm using custom drawing both for my UITableViewCell and my <code>MapIcon</code> (custom map view) that I add to my UITableViewCell.</p> <p><code>MapIcon</code> is a subclass of <code>MKMapView</code> and the drawing method looks as follows:</p> <blockquote> <p>-(void)drawRect:(CGRect)rect {</p> <pre><code>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); </code></pre> <p>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);</p> <pre><code>CGContextDrawPath(context, kCGPathFillStroke); </code></pre> <p>CGContextClip(context); CGContextEndTransparencyLayer(context); }</p> </blockquote> <p>And the maps do not get the corners rouned, as can be seen in the below screenshot:</p> <p><a href="http://img190.imageshack.us/img190/948/picture1vmk.png">alt text http://img190.imageshack.us/img190/948/picture1vmk.png</a></p> <p>If however I change the <code>MapIcon</code> to subclass from UIView and use the same custom drawing methods, the view gets clipped perfectly, image below:</p> <p><a href="http://img503.imageshack.us/img503/6269/picture2xkq.png">alt text http://img503.imageshack.us/img503/6269/picture2xkq.png</a></p> <p>Is it wrong for me to subclass MKMapView in such a way and expect it to clip? Any other any of rounding these corners?</p> <p>Cheers, Kaspa </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload