4

I am building my custom UIControl, a custom button built as an IBDesignable, which needs to change based on the size class in which it is being displayed. I have a method -setupForTraitCollection, which looks like this:

func setupForTraitCollection() {
   switch(traitCollection.horizontalSizeClass, traitCollection.verticalSizeClass) {
   case (.Regular, _):
       // iPad - not compressed design
       compressed = false
   default:
       // iPhone - compressed design
       compressed = true
   }
}

This code works great when compiled, but in live rendering, and when debugging the view, it never hits the "iPad" switch case. I am starting to give up here and simply accept that traitCollections aren't available in live rendering, but I'd like to have this confirmed. Better still, if someone could point me in the direction of finding a solution.

So the to-the-point question is - Can I use traitCollections in an IBDesignable and if so, how?

I'd really like to be able to change size class in IB and see the result on my custom control.

jollyCocoa
  • 691
  • 7
  • 20
  • Did you find a solution for this I've got exactly the same problem? Or do you have a workaround? – Jules Nov 15 '15 at 19:38

1 Answers1

2

Interface Builder does not yet set the trait collection for designable views when we are rendering in Xcode. We are tracking this with radar://17278773. Filing a report at http://bugreport.apple.com and mentioning that bug ID will help us track demand and prioritize appropriately.

Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
  • Can you file this on http://openradar.appspot.com I've just had apple say that my report is a duplicate on yours, but obviously we can't see other peoples radars. Thanks. – Jules Nov 24 '15 at 06:56
  • Sorry Jules, that is an Apple internal bug (I'm the one who marked your bug as a duplicate) and Apple employees generally don't post on OpenRadar. :-) However, please feel free to post the details in your bug (radar://23549463) there; if someone references your bug ID, we will still find the right bug to dupe it to. – Quinn Taylor Nov 25 '15 at 22:06
  • I'm not sure what extra details would be useful that I haven't already mentioned ? – Jules Nov 25 '15 at 22:38
  • Apologies, let me clarify further. If you'd like to post the details you already provided in *your* bug on OpenRadar, so other developers can see, you certainly can. I wasn't requesting any further details to assist Apple engineering, we have a good grasp on the issue. – Quinn Taylor Jun 18 '16 at 21:35
  • Thanks, is it at useful to file bugs following crash submission, where the crash is shown in the dialog with the reopen button? – Jules Jun 18 '16 at 21:38
  • Having said that I'm not sure what further to add, I guess I'm refereeing to a crash not related to this issue when I'm opening a project, where I've no idea why the crash occurred – Jules Jun 18 '16 at 21:40