【发布时间】:2020-08-07 07:32:32
【问题描述】:
【问题讨论】:
-
寻找 UIBezierPath,在你的情况下一个带角半径的矩形应该足够了。
-
你能分享一些代码sn-ps吗?这对我有很大帮助
-
你可以只使用cornerRadius ...
【问题讨论】:
我曾尝试使用 UIView 克隆类似的视图,并且能够创建类似的 UI,正如您在屏幕截图 中所说的那样
这是我的代码 sn-p
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)
希望这对您有所帮助。美好的一天。
【讨论】:
你可以像这样画椭圆路径
class CustomOval: UView {
override func drawRect(rect: CGRect) {
var ovalPath = UIBezierPath(ovalIn: rect)
UIColor.gray.setFill()
ovalPath.fill()
}
}
【讨论】: