ios - 中间透明的UIView

标签 ios objective-c uiview transparent

enter image description here

是否可以创建这样一个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/

相关文章:

ios - UITableView 最后一行被截断

ios - 将 MKMapView 移动到相对于父 View 的特定位置

ios - UIIView Inside UITableView 将 Frame 高度更改为 0 或 60

iphone - 确定 UIView 对用户是否可见?

ios - 如何处理从另一个应用程序共享到我自己的 iOS 应用程序的文件?

ios - 如何在 Swift beta 3 中从 UIImagePickerControllerDelegate 获取 UIImage?

ios - 如何以编程方式更改detailTextLabel高度

ios - 将一个 View 方向更改为横向

c++ - 未在此范围内声明 msgStore (XCode)

ios - 将 UIImageView 裁剪到父级的边界