ios - 如何在 UIView 中屏蔽 UIImage View ?

标签 ios swift uiview uiimage core-graphics

我试图将 subview 屏蔽到 super View ,但 ImageView 没有屏蔽到 super View

显示方式 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) mask 层

2)剪切图像

最佳答案

制作具有像您的角落一样的图层的新图像,并将其作为蒙版放在您的 View 上。

关于ios - 如何在 UIView 中屏蔽 UIImage View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41299587/

相关文章:

Swift:如何在从另一个 VC 单击 TableViewCell 后导航到 PDF 页面

ios - 以编程方式更改 UIView 的位置

ios - 打印标签时没有出现相机预览

充当信标的 Android 设备

ios - Swift UIScrollView 不滚动但响应 setContentOffset 和 Delegate 响应

ios - 如何通过点击 swift 中的按钮来创建新 View (或 subview )?

swift - UIView图层蒙版动画

ios - 追踪 xcode 堆栈跟踪时遇到问题

ios - swift:从数组中添加值

ios - 每当激活带有链接的 TextView 时,应用程序就会崩溃并出现画外音