IBDesignables and traitCollection in live rendering

有些话、适合烂在心里 提交于 2019-12-31 00:57:25

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/28444097/ibdesignables-and-traitcollection-in-live-rendering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!