0

I've been developing an app in XCode 7 and all was well. I thought "hey, let's update to iOS 10" so opened up the project in XCode 8 and started fixing warnings and looking for issues.

Now it seems that UIViews load up with blank backgrounds, either from storyboard or created in code. In storyboard I have a UIView with a redColor background but the first time it's displayed (in a UICollectionViewCell) it appears with a clearColor background, or so it would appear, debugging it everything looks fine under the hood. When I swipe away from the cell and come back to that same cell (either by swiping back or the cell being recycled) it gets its correct colour... I've tried [cell setNeedsDisplay] and [cell setNeedsLayout] to no avail...

Even if I try and set the backgroundColor in my code it doesn't help how it looks when initially displayed.

Nothing unexpected is setting the background colour (checked by making a custom class that overrides the function) and the view isn't hidden, nor has 0 alpha (subviews show fine).

I should point that is seems to be clearColor because some subview UILabels I've got are still showing up ok.

I don't think there's any more information I can provide but feel free to ask!

EDIT: Turns out the backgroundColor is probably being honoured fine but something odd is going on with the layout of the view. The frame seems fine but if I use clipsToBounds then my subview labels disappear so the views frame must be off-screen somewhere or zero-sized...

CMash
  • 1,987
  • 22
  • 35
  • 1
    Do you by any chance have a `[UIView appearance]` set anywhere? I can confirm views are white by default in iOS 10, too. – Ramon Sep 26 '16 at 13:58
  • Nothing for `UIView` no (just `UINavigationBar` and `UIBarButton`). – CMash Sep 26 '16 at 14:05
  • Can you log the background color of the cell? – Mike Sep 26 '16 at 14:41
  • Yep, the `backgroundColor` always logs out as the colour I would expect but seems to show up as `clearColor` when rendered. But when the cell gets recycled it gets its correct colour. – CMash Sep 26 '16 at 14:44
  • What do you mean it shows up as clearColor when rendered? Is it invisible? How do you know its even there? Is the frame correct? – Mike Sep 26 '16 at 14:47
  • It's as if it's invisible but it has `subviews` that show up fine (`UILabel`s which incidentally show their `backgroundColor` without issue). – CMash Sep 26 '16 at 14:49
  • 1
    What is the view's frame? I'm guessing there's some issue with the size of the view, perhaps the height is 0 or something. – Mike Sep 26 '16 at 14:51
  • I think you're onto something there Mike... The frame looks fine but if I set `clipsToBounds` to `YES` then my `UILabels` disappear... – CMash Sep 26 '16 at 15:02

2 Answers2

2

Seems like a bug in XCode 8 storyboards. Once Mike had helped me whittle it down to being some kind of layout issue I started searching on that instead of a backgroundColor issue and came across this useful thread: https://stackoverflow.com/a/39589860/1751266

If you revert the storyboard back to XCode 7 format then everything works again. Unfortunately you have to do that every time you make a change to the storyboard. But hey, it works...

Community
  • 1
  • 1
CMash
  • 1,987
  • 22
  • 35
0

I had this problem and it does seem related to layout. In my case I just had to "Clear all Constraints" from the affected view and then the background color was rendered properly.

biomiker
  • 3,108
  • 1
  • 29
  • 26