內(nèi)外cornerRadius可以控制
baseLayer是我們?cè)嫉膱D層泽谨,現(xiàn)在想截取圓角矩形出來窘哈,中間挖空成一個(gè)圓角矩形匠襟。
CAShapeLayer* cropLayer = [[CAShapeLayer alloc] init];
[baseLayer addSublayer:cropLayer];
// 創(chuàng)建一個(gè)繪制路徑
CGMutablePathRef mPath =CGPathCreateMutable();
// 空心矩形的rect(即要挖空的內(nèi)部區(qū)域)
CGRect cropRect = CGRectMake(10, 10, 60, 40);
// 繪制rect
CGPathAddRoundedRect(mPath, nil, baseLayer.bounds, 5, 5);
CGPathAddRoundedRect(mPath, nil, cropRect, 5, 5);
// 設(shè)置填充規(guī)則(重點(diǎn))
[cropLayer setFillRule:kCAFillRuleEvenOdd];
// 關(guān)聯(lián)繪制的path
[cropLayer setPath:mPath];
// 設(shè)置填充的顏色
[cropLayer setFillColor:[[UIColor greenColor] CGColor]];