swift - 以编程方式在屏幕上快速绘制自定义椭圆形
解决方案
我尝试使用 UIView 克隆类似的视图,并且能够创建类似的 UI,如您在屏幕截图中所述
这是我的代码片段
let width: CGFloat = view.frame.size.width
let height: CGFloat = view.frame.size.height
let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: self.view.bounds.size.width, height: self.view.bounds.size.height), cornerRadius: 0)
let rect = CGRect(x: width / 2 - 150, y: height / 2.5 - 100, width: 300, height: 400)
let circlePath = UIBezierPath(ovalIn: rect)
path.append(circlePath)
path.usesEvenOddFillRule = true
let fillLayer = CAShapeLayer()
fillLayer.path = path.cgPath
fillLayer.fillRule = .evenOdd
fillLayer.fillColor = UIColor.red.cgColor
fillLayer.opacity = 0.5
view.layer.addSublayer(fillLayer)
希望这对您有所帮助。再会。
推荐阅读
- tectonic-coreos - 无法下载构造沙盒
- android - Google Play 服务未出现在 Unity 中
- javascript - 如何使用单独的 js 文件打包一个多页面(tsx)网站?
- akka - akka cluster/remoting 在大容量、较慢的订阅者上死了
- python-3.x - 使用 Selenium 和 Python 填写搜索表单
- javascript - 从嵌套的 json 响应中提取数据
- javascript - 向下滑动导航栏重叠
- powershell - Powershell 静默卸载“Microsoft Report Viewer Runtime 2012”
- aurelia - Aurelia UX 展示应用程序无法加载
- c - “返回”数组时的静态或指针