如何在UIView中屏蔽UIImage视图?

时间:2016-12-23 10:24:02

标签: ios swift uiview uiimage core-graphics

我试图将子视图屏蔽为超级视图,但图像视图未被屏蔽为超级视图

如何显示 OUTPUT

如何假设

OUTPUT 2

代码

class TicketView: UIView {

    var img = UIImage(named: "social-event.jpg")
    var imageView = UIImageView()

    override func draw(_ rect: CGRect) {
        let path = UIBezierPath(rect: rect)
        let width:CGFloat = 11
        let height:CGFloat = 11
        let roundLeft = UIBezierPath(roundedRect: CGRect(x: -(width/2), y: -(height/2), width: width, height: height), cornerRadius: (height/2))
        let roundLeftBotton = UIBezierPath(roundedRect: CGRect(x: -(width/2), y: (rect.height)-(height/2), width: width, height: height), cornerRadius: (height/2))
        let roundRight = UIBezierPath(roundedRect: CGRect(x: (rect.width)-(width/2), y: -(height/2), width: width, height: height), cornerRadius: (height/2))
        let roundRightBottom = UIBezierPath(roundedRect: CGRect(x: (rect.width)-(width/2), y: (rect.height)-(height/2), width: width, height: height), cornerRadius: (height/2))

        let roundRightMiddle = UIBezierPath(roundedRect: CGRect(x: (rect.width*0.7)-(width/2), y: -(height/2), width: width, height: height), cornerRadius: (height/2))
        let roundRightMiddleBottom = UIBezierPath(roundedRect: CGRect(x: (rect.width*0.7)-(width/2), y:
            (rect.height)-(height/2), width: width, height: height), cornerRadius: (height/2))
        path.append(roundLeft.reversing())
        path.append(roundLeftBotton.reversing())
        path.append(roundRight.reversing())
        path.append(roundRightBottom.reversing())
        path.append(roundRightMiddle.reversing())
        path.append(roundRightMiddleBottom.reversing())

        UIColor.green.setFill()
        path.fill()

        imageView.frame = CGRect(x: 0, y: 0, width: (rect.width * 0.7),  height: rect.height)
        imageView.backgroundColor = UIColor.black
        self.addSubview(imageView)


    }

}

我到现在为止尝试了什么

1)遮罩层

2)剪切图像

1 个答案:

答案 0 :(得分:0)

制作包含角落图层的新图像,并将视图作为蒙版放置。