gpt4 book ai didi

iphone - MKMapView 的圆角

转载 作者:行者123 更新时间:2023-12-03 18:33:22 24 4
gpt4 key购买 nike

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

我正在为 UITableViewCell 和添加到 UITableViewCell 的 MapIcon(自定义 map View )使用自定义绘图。

MapIconMKMapView的子类,绘制方法如下:

-(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); }

并且 map 的角没有变圆,如下面的屏幕截图所示:

alt text http://img190.imageshack.us/img190/948/picture1vmk.png

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

alt text http://img503.imageshack.us/img503/6269/picture2xkq.png

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

干杯,卡斯帕

最佳答案

制作圆角的最简单方法:

#import <QuartzCore/QuartzCore.h>
myMapView.layer.cornerRadius = 10.0;

关于iphone - MKMapView 的圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1351351/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com