IBDesignables and traitCollection in live rendering
Asked Answered
N

1

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.

Nenitanenney answered 10/2, 2015 at 23:50 Comment(1)
Did you find a solution for this I've got exactly the same problem? Or do you have a workaround?Cence
C
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.

Croat answered 19/11, 2015 at 17:37 Comment(6)
Can you file this on 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.Cence
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.Croat
I'm not sure what extra details would be useful that I haven't already mentioned ?Cence
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.Croat
Thanks, is it at useful to file bugs following crash submission, where the crash is shown in the dialog with the reopen button?Cence
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 occurredCence

© 2022 - 2024 — McMap. All rights reserved.