首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在UIImage中屏蔽UIView视图?

如何在UIImage中屏蔽UIView视图?
EN

Stack Overflow用户
提问于 2016-12-23 10:24:01
回答 1查看 344关注 0票数 0

我试图将子视图伪装成超级视图,但是图像视图并不被屏蔽为超级视图。

如何显示

它怎么会是

代码语言:javascript
复制
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)切割图像

EN

回答 1

Stack Overflow用户

发布于 2016-12-23 10:39:02

制作新的图像,有图层,就像你的角落,并把你的观点作为一个面具。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41299587

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档