import UIKit
@IBDesignable
class DiagonalCustomImageView: UIImageView {
// 숫자라고 Int 타입만 쓰면 안됨 타입을 확인 해야 함
@IBInspectable var innerHeight: CGFloat = 150
func makePath() -> UIBezierPath {
let path = UIBezierPath()
// 선 긋는 좌표 지정
// path의 시작점은 move / cgpoint는 해당하는 좌표
path.move(to: CGPoint.zero)
// 그리기, 이미지 뷰의 끝으로 이동 y는 움질일 필요가 없으므로 0
path.addLine(to: CGPoint.init(x: self.bounds.width, y: 0))
// x축은 유지한 상태로 이미지 뷰의 높이 만큼 y축 이동
path.addLine(to: CGPoint.init(x: self.bounds.width, y: self.bounds.height))
// y에서 -50만큼 이동 후 왼쪽으로 끝까지 이동
path.addLine(to: CGPoint.init(x: 0, y: self.bounds.height - innerHeight))
path.close()
return path
}
func pathToLayer() -> CAShapeLayer {
let shapeLayer = CAShapeLayer()
shapeLayer.path = makePath().cgPath
return shapeLayer
}
func makeMask() {
self.layer.mask = pathToLayer()
}
// 해당하는 오브젝트가 그려질때
override func layoutSubviews() {
makeMask()
}
}