I switched my project over to new beta versions of iOS 10 and XCode 8. In all three areas of my app where I use:
imageView.layer.cornerRadius = imageView.frame.size.width/2
imageView.clipsToBounds = true
The associated images are not displaying at all. I have attempted cleaning the project as well as the build folder, restarting the device, trying on various simulators, re-adding the imageView, programmatically setting the associated UIImage
instead of choosing one from the assets.
Removing the clipsToBounds
line shows the rectangular image regardless of whether masksToBounds
is true
or false
. How can I make a circular image in XCode8 / iOS10 ?
Edit: The project is Swift 2.x and not yet updated to Swift 3.0 syntax.
I had the same problem and calling
layoutIfNeeded
before all the rounded corner /clipsToBounds
stuff fixed the issue. iOS 10 GM with xcode 8 GM causes views to disappear due to roundedCorners & clipsToBoundsThis problem also happened to me.
I moved these code
imageView.layer.cornerRadius = imageView.frame.size.width/2
from- (void)awakeFromNib
to- (void)drawRect:(CGRect)rect
and this problem went away.My imageView is sized by autolayout. I think that height and width are not decided when awaking from nib on iOS 10.
Using obj-c, moving the syntax from
viewDidLoad
toviewDidLayoutSubviews
worked for me.I had the same problem. Not showing on the phone, but perfect on Storyboard and UI debugger. It was also working when I was putting the project "Opens with Xcode 7" instead of 8 but wasn't a satisfying solution. So I digged and found out the problem. The trouble was with a class looking like this :
I changed it to this and it works now :
Note that none of the above worked for me, and I mean :
layoutIfNeeded
in thelayoutSubviews()
layoutIfNeeded
in theawakeFromNib
of my button (or my cell containing the button)layoutIfNeeded
in thelayoutSubview
of my cellcontentView.layoutIfNeeded()
in theawakeFromNib
of my cellview.layoutIfNeeded()
in my view controllerI had ImageView that is fully circular in shape. Below is code :
This works fine in iOS 9. However,
in iOS 10 Xcode 8 the ImageView disappears.
After debugging found that ClipsToBound is culprit.So placed the code in
viewDidLayoutSubviews()
resolved the issue.You can also use
self.view.layoutIfNeeded()
You should call layoutSubviews() on the main view before call imageView.frame.size.width