2

as seen in radar (28342777) - there is an issue in iOS10 when creating UIImageView. Since the views are made automatically to (1000x1000px) sometimes they won't display.

turning off masksToBounds will make them appear correctly, but don't allow to make the circular. I tried using cornerRadius by itself, but it won't work.

Is there a work around?

JVS
  • 2,592
  • 3
  • 19
  • 31
  • Can you not init the view with a smaller frame on instantiation? – Woodstock Sep 23 '16 at 13:46
  • I have done that in IB. I have constraints on it saying width = height = 64. But it doesn't change – JVS Sep 23 '16 at 13:47
  • 1
    could you try subclassing it, having your own custom init that calls init and sets the frame subsequently, that way it's done for you before the image is set? – Woodstock Sep 23 '16 at 13:48
  • @Woodstock not sure how to do this. I am using custom TableViewCells with UIImageView. Do I need to code this in my customCell class ? – JVS Sep 23 '16 at 13:49
  • 1
    actually I think there is an even easier solution shown here, check it out: http://stackoverflow.com/questions/39475456/ios10-viewdidload-frame-width-height-not-initialized-correctly – Woodstock Sep 23 '16 at 13:50
  • 1
    @Woodstock okay got a solution with your help now. In my cell class i put just above masksToBounds = true - self.layoutIfNeeded(). I also needed to call self.userInteractionEnabled = true – JVS Sep 23 '16 at 13:58

1 Answers1

1

If you need to make your UIImageView circular, you have to do this in viewDidLayoutSubviews instead of viewDidLoad method, as:

override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        self.yourImageView.layer.cornerRadius = self.yourImageView.frame.size.height/2
        self.yourImageView.clipsToBounds = true

    }
Aakash
  • 2,239
  • 15
  • 23