ios10: viewDidLoad frame width/height not initialized correctly

前端 未结 7 958
闹比i
闹比i 2020-12-07 20:23

Since upgrading to XCode8 GM and ios10, all of my views created via Interface Builder are not being initialized correctly until much much later than expected. This means in

7条回答
  •  眼角桃花
    2020-12-07 21:09

    I was having the exact same problem. I had custom UITableViewCell subclasses and was using clipsToBounds = YES and self.iconView.layer.cornerRadius = self.iconView.frame.size.width/2 to give myself a circular image. Tried calling my cell configuration method from cellForRowAtIndexPath and willDisplayCell and neither worked.

    Here is what works:
    Move your layering code into the cell's -layoutSubviews method like this:

    -(void)layoutSubviews {
        [super layoutSubviews];
        self.iconView.clipsToBounds = YES;
        self.iconView.layer.cornerRadius = self.iconView.frame.size.width/2;
    } 
    

    After this the images should load properly and your layering code should also work.

提交回复
热议问题