I have a problem.
I want to make the view about the corner like this but I don't know how to do this:
i want to make this corner view
I also followed this Stackoverflow question question url.
extension UIView {
func roundCorners(corners:UIRectCorner, radius: CGFloat) {
let mask = CAShapeLayer()
mask.path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)).cgPath
layer.mask = mask
}
so I use corner function in layoutsubview
//var labelContent:UILabel
override func layoutSubviews() {
super.layoutSubviews()
labelContent.roundCorners(corners: [.bottomLeft,.topLeft,.topRight], radius: 10)
}
it work but when i scroll up ,the cell view is disappear.
so, i use second function.
but it doesnt work, too
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let cell: ChatContentTableViewCell = ChatContentTableViewCell(style: .default, reuseIdentifier: nil)
let maskPathTop = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [.bottomRight], cornerRadii: CGSize(width: 0, height: 0))
let shapeLayerTop = CAShapeLayer()
shapeLayerTop.frame = cell.labelContent.bounds
shapeLayerTop.path = maskPathTop.cgPath
}
update: i follow Mr. Hedgehog suggestion:
when i scroll up , the cell view disappear.
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
guard let cell = cell as? ChatContentTableViewCell else { return }
let maskPathTop = UIBezierPath(roundedRect: cell.contentView.bounds, byRoundingCorners: [.bottomRight], cornerRadii: CGSize(width: 0, height: 0))
let shapeLayerTop = CAShapeLayer()
shapeLayerTop.frame = cell.contentView.bounds
shapeLayerTop.path = maskPathTop.cgPath
}