MKMapView的圆角

Kas*_*spa 8 iphone uitableview

我正在构建一个自定义UITableView,其中每个单元格都包含一段文本和一个MKMapView.我希望单元格中的地图"图标"视图有圆角,这似乎是一个问题.

我正在为我的UITableViewCell和我MapIcon添加到UITableViewCell的(自定义地图视图)使用自定义绘图.

MapIcon是一个子类,MKMapView绘图方法如下所示:

- (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);   
Run Code Online (Sandbox Code Playgroud)

CGContextBeginPath(上下文); CGContextMoveToPoint(context,Xmin,Ymid); CGContextAddArcToPoint(context,Xmin,Ymin,Xmid,Ymin,radius); CGContextAddArcToPoint(context,Xmax,Ymin,Xmax,Ymid,radius); CGContextAddArcToPoint(上下文,Xmax,Ymax,Xmid,Ymax,radius); CGContextAddArcToPoint(context,Xmin,Ymax,Xmin,Ymid,radius); CGContextClosePath(上下文);

CGContextDrawPath(context, kCGPathFillStroke);
Run Code Online (Sandbox Code Playgroud)

CGContextClip(上下文); CGContextEndTransparencyLayer(上下文); }

并且地图不会被扯到角落,如下面的屏幕截图所示:

替代文字http://img190.imageshack.us/img190/948/picture1vmk.png

但是,如果我MapIcon从UIView 更改子类并使用相同的自定义绘图方法,则视图会被完美剪切,如下图所示:

替代文字http://img503.imageshack.us/img503/6269/picture2xkq.png

以这种方式将MKMapView子类化并期望它剪辑是错误的吗?这些角落还有其他任何一个吗?

干杯,卡斯帕

dig*_*dog 41

制作圆角的最简单方法:

#import <QuartzCore/QuartzCore.h>
myMapView.layer.cornerRadius = 10.0;
Run Code Online (Sandbox Code Playgroud)