UIView is always rectangular. However, you can make him look around (or any shape in general) with a mask. To do this, make a UIImage, which is a black circle (on a transparent background). Now take the CGImage of this UIImage and make it the contents of CALayer. Finally, set CALayer as the mask layer of your view.
Suppose your view is 100 x 100. Then (not tested, but should be very correct):
UIGraphicsBeginImageContextWithOptions(CGSizeMake(100,100), NO, 0); CGContextRef c = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(c, [UIColor blackColor].CGColor); CGContextFillEllipseInRect(c, CGRectMake(0,0,100,100)); UIImage* maskim = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); CALayer* mask = [CALayer new]; mask.frame = CGRectMake(0,0,100,100); mask.contents = (id)maskim.CGImage; view.layer.mask = mask;
matt May 10 '13 at 5:35 2013-05-10 05:35
source share