image disappears when styling class to make a round image

前端 未结 2 695
执笔经年
执笔经年 2021-01-21 13:54
class RoundImage: UIImageView {

    override func awakeFromNib() {
        super.awakeFromNib()
        setupView()
    }

     ...

    func setupView() {
        self         


        
2条回答
  •  北海茫月
    2021-01-21 13:59

    When this code gets run the view hasn't been sized yet, so the width is incorrect. Try putting a listener on frame:

    override var frame : CGRect {
        didSet {
            layer.cornerRadius = frame.size.width / 2
        }
    }
    

提交回复
热议问题