อีกวิธีหนึ่งในการเข้าใกล้วงกลม (และรูปร่างอื่น ๆ ) คือการใช้มาสก์ คุณวาดวงกลมหรือรูปทรงอื่น ๆ โดยขั้นแรกสร้างมาสก์ของรูปทรงที่คุณต้องการอันดับสองใส่สี่เหลี่ยมของสีของคุณและอย่างที่สามใช้มาสก์กับสี่เหลี่ยมสีเหล่านั้น คุณสามารถเปลี่ยนหน้ากากหรือสีเพื่อรับวงกลมที่กำหนดเองใหม่หรือรูปร่างอื่น ๆ
#import <QuartzCore/QuartzCore.h>
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *area1;
@property (weak, nonatomic) IBOutlet UIView *area2;
@property (weak, nonatomic) IBOutlet UIView *area3;
@property (weak, nonatomic) IBOutlet UIView *area4;
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.area1.backgroundColor = [UIColor blueColor];
    [self useMaskFor: self.area1];
    self.area2.backgroundColor = [UIColor orangeColor];
    [self useMaskFor: self.area2];
    self.area3.backgroundColor = [UIColor colorWithRed: 1.0 green: 0.0 blue: 0.5 alpha:1.0];
    [self useMaskFor: self.area3];
    self.area4.backgroundColor = [UIColor colorWithRed: 1.0 green: 0.0 blue: 0.5 alpha:0.5];
    [self useMaskFor: self.area4];        
}
- (void)useMaskFor: (UIView *)colorArea {        
    CALayer *maskLayer = [CALayer layer];
    maskLayer.frame = colorArea.bounds;
    UIImage *maskImage = [UIImage imageNamed:@"cirMask.png"];
    maskLayer.contents = (__bridge id)maskImage.CGImage;
    colorArea.layer.mask = maskLayer;
}
@end
นี่คือผลลัพธ์ของโค้ดด้านบน:
