是否可以创建这样一个UIView
填充颜色,但中间是透明的?
我正在考虑在这里创建 5 UIView
。只是想知道是否可以仅使用一个 UIView
最佳答案
来自 Duncan C ,我知道我应该从哪里开始,然后我找到了 CALayer with transparent hole in it .
UIBezierPath *overlayPath = [UIBezierPath bezierPathWithRect:self.view.bounds];
UIBezierPath *transparentPath = [UIBezierPath bezierPathWithRect:CGRectMake(60, 120, 200, 200)];
[overlayPath appendPath:transparentPath];
[overlayPath setUsesEvenOddFillRule:YES];
CAShapeLayer *fillLayer = [CAShapeLayer layer];
fillLayer.path = overlayPath.CGPath;
fillLayer.fillRule = kCAFillRuleEvenOdd;
fillLayer.fillColor = [UIColor colorWithRed:255/255.0 green:20/255.0 blue:147/255.0 alpha:1].CGColor;
[self.view.layer addSublayer:fillLayer];
利用2个UIBezierPath
,然后填充我想要的颜色(我的问题是粉红色),然后添加为子层
关于ios - 中间透明的UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24196784/