【发布时间】:2011-08-25 21:14:47
【问题描述】:
我正在尝试为我正在构建的其中一个应用程序制作一个很酷的效果,并且宁愿不使用 drawRect 函数。你们能想出一个简单的方法在 UIImage 周围放置一个漂亮的圆形边框吗?它应该看起来像一个圆形相框。
这是我目前使用的:
CGFloat radius = self.layer.bounds.size.width / 2;
CAShapeLayer *mask = [CAShapeLayer layer];
mask.frame = self.layer.bounds;
[mask setFillColor:[[UIColor whiteColor] CGColor]];
CGFloat width = self.layer.bounds.size.width;
CGFloat height = self.layer.bounds.size.height;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, width, 0);
CGPathAddLineToPoint(path, NULL, width, height - radius);
CGPathAddCurveToPoint(path, NULL, width, height, width - radius, height, width - radius, height);
CGPathAddLineToPoint(path, NULL, 0, height);
CGPathAddLineToPoint(path, NULL, 0, radius);
CGPathAddCurveToPoint(path, NULL, 0, 0, radius, 0, radius, 0);
CGPathCloseSubpath(path);
[mask setPath:path];
CGPathRelease(path);
self.layer.mask = mask;
[self setNeedsDisplay];
我的 UIImage 被封装在一个 UIView 中(self 是一个 UIView)。我期待它在我的 UIView 周围画一个圆圈。
【问题讨论】:
-
您是在问如何在不使用视图的情况下绘制图像,还是在问是否可以在不实际绘制的情况下绘制图像?
-
我正在尝试在我的图像周围画一个圆圈
标签: iphone objective-c ios