I am trying to make a cool effect for one of the applications that I create, and would rather not guess with the drawRect function. Can you guys think of a simple way to put a circular border around a UIImage? It should look something like a round frame.
Here is what I use so far:
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];
My UIImage is encapsulated in UIView (self - UIView). I expect him to draw a circle around my UIView.
source share