IBDesignables和traitCollection在现场渲染 [英] IBDesignables and traitCollection in live rendering

查看:177
本文介绍了IBDesignables和traitCollection在现场渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建我的自定义UIControl,一个自定义按钮构建为一个IBDesignable,需要根据其显示的大小类别更改。我有一个方法-setupForTraitCollection,它看起来像这样:

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
   }
}

工作伟大的编译时,但在实时渲染,当调试视图,它从来没有击中iPad开关盒。我开始放弃在这里,只是接受traitCollections不可用的实时渲染,但我想有这个确认。更好的是,如果有人可以指出我的方向找到一个解决方案。

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.

所以点对点问题是 - 我可以使用traitCollections IBD可设置,如果可以,如何?

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

我真的很想改变IB中的大小班级,看看我的自定义控件的结果。 / p>

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

推荐答案

当我们在Xcode中渲染时,Interface Builder尚未设置可设计视图的trait集合。我们正在跟踪这个雷达:// 17278773。在 http://bugreport.apple.com 提交报告,并提及错误ID将帮助我们跟踪需求和优先级

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.

这篇关于IBDesignables和traitCollection在现场渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆