У меня есть пользовательский xib, созданный вместе с UIBezierpath, и когда я добавляю изображение в закрытый раздел этого UIBezierCurve, изображение не отображается. Есть ли способ добавить изображение поверх закрытого раздела UIBezierpath.
Изображение должно отображаться в белом разделе
введите описание изображения здесь
Код, как показано ниже
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = Bundle.main.loadNibNamed(TableViewCells.ForgotPwCell.rawValue, owner: self, options: nil)?.first as! ForgetPasswordTableViewCell
let shape = Utils.drawBazierCurve(width: tableView.frame.width, height: tableView.frame.height)
cell.contentView.layer.addSublayer(shape)
let theImage = UIImage(named: "forgot_pw.png") // create a UIImage
cell.forgotpwImageVw.image = theImage
return cell
}
Метод создания пути, как показано ниже
static func drawBazierCurve(width:CGFloat,height:CGFloat) -> CAShapeLayer {
let path = UIBezierPath()
let controlPoint1 = CGPoint(x: (3/8)*width, y: (4/18)*height)
let controlPoint2 = CGPoint(x: (6/8)*width, y: (8/18)*height)
let end = CGPoint(x: width, y: (6/18)*height)
path.move(to: CGPoint(x: 0, y: height/2))
path.addCurve(to: end, controlPoint1: controlPoint1, controlPoint2: controlPoint2)
path.addLine(to: CGPoint(x: width, y: 0))
path.addLine(to: CGPoint(x: 0, y: 0))
path.close()
let shape = CAShapeLayer()
shape.path = path.cgPath;
shape.fillColor = UIColor.white.cgColor
return shape
}