image disappears when styling class to make a round image

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

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

     ...

    func setupView() {
        self         


        
2条回答
  •  醉梦人生
    2021-01-21 14:08

    I faced with this problem a few days ago. You should add layoutIfNeeded() before layer modifications.

    In your case:

    func setupView() {
            self.layoutIfNeeded()
            self.layer.borderWidth = borderWidth
            self.layer.borderColor = borderColor
            self.clipsToBounds = clip
            self.layer.cornerRadius = self.frame.size.width / 2
     }
    

提交回复
热议问题