制作固定大小的UIView,如UISwitch(使用IBDesignable) [英] Make a fixed size UIView, like UISwitch (using IBDesignable)

查看:149
本文介绍了制作固定大小的UIView,如UISwitch(使用IBDesignable)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用本指南创建一个在XIB中设计的视图,可以在故事板中使用我的UIView子类上的IBDesignable属性重用,如何使其具有固定大小,以及它的调整大小行为与UISwitch之类的视图相匹配吗?

When I'm using this guide to create a view that is designed in a XIB, reusable from within a storyboard using the IBDesignable attribute on my UIView subclass, how do I make it have a fixed size, and have its resizing behavior match that of a view like UISwitch?

使用调整大小行为我在设计界面构建器时也是指。

With "resizing behavior" I also mean while designing in interface builder.

推荐答案

您可以在 UIView intrinsicContentSize() >子类。
然后你不需要在界面构建器中提供高度和宽度约束。

You could override intrinsicContentSize() in your UIView subclass. Then you won't need to supply height and width constraints in the interface builder.

override func intrinsicContentSize() -> CGSize {
    return CGSizeMake(100, 100)
}

这篇关于制作固定大小的UIView,如UISwitch(使用IBDesignable)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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