我正在构建一个定制的UITableView,每个单元格都包含一个文本和一个MKMapView。我希望地图“图标”视图在单元格中有圆角,这似乎是一个问题。
我正在为我的UITableViewCell和MapIcon (自定义地图视图)使用自定义绘图,这两个视图都添加到了我的UITableViewCell中。
MapIcon是MKMapView的子类,绘图方法如下所示:
-(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 Ymid =(Rect);#en22 20# Ymax =(Rect);(上下文);(上下文,Xmin,Ymid);en24#(上下文,Xmin,Xmid,radius);CGContextAddArcToPoint(上下文,Xmax,Ymin,Xmax,Ymid,radius);CGContextAddArcToPoint(上下文,Xmax,Xmin,Ymax,半径);CGContextAddArcToPoint(上下文,Xmin,Ymax,Xmin,Ymid,radius);CGContextClosePath(上下文) CGContextDrawPath(上下文,kCGPathFillStroke); CGContextClip(上下文);CGContextEndTransparencyLayer(上下文);}
而这些地图并没有把拐角处围成圆形,就像下面的截图所示:
alt文本http://img190.imageshack.us/img190/948/picture1vmk.png
但是,如果我将MapIcon更改为UIView中的子类并使用相同的自定义绘图方法,则视图将被完美地剪裁,如下所示:
alt文本http://img503.imageshack.us/img503/6269/picture2xkq.png
对我来说,以这种方式子类MKMapView并期望它剪辑是错误的吗?还有其他围在这些角落里的吗?
干杯,卡斯帕
发布于 2009-08-29 17:04:26
做圆角最简单的方法是:
#import <QuartzCore/QuartzCore.h>
myMapView.layer.cornerRadius = 10.0;发布于 2010-09-12 18:15:51
只是一个小小的更正,因为导入语句在迪克特的回答中拼写错误。
应该是
#import <QuartzCore/QuartzCore.h>
myMapView.layer.cornerRadius = 10.0;发布于 2009-08-29 14:52:45
查看一下MKMapView类引用中概述部分的最后一段
尽管不应该子类MKMapView类本身,.
我认为这很好地回答了你的问题,你是否应该细分它。您可以做的一件事是将另一个视图放在MKMapView的顶部,这个视图看起来像环绕角落的背景。如果您需要它的大小是任意的,您可以在strechableImage上尝试UIImage方法。
https://stackoverflow.com/questions/1351351
复制相似问题