iOS中自定义UIView如何更改子view的布局

autolayout不说了,看下frame布局的情况。

我们假设subview永远和当前view尺寸一样。则:

class YourView: UIView {
.....
    override func layoutSubviews() {
        super.layoutSubviews()
        let frame1 = CGRect(x: 0, y: 0, width: frame.width, height: frame.height)
        view1.frame = frame1

        let frame2 = CGRect(x: 0, y: 0, width: frame.width, height: frame.height)
        view1.frame = frame2
    }
...
}

这样就可以了。

Leave a Reply

Your email address will not be published. Required fields are marked *