xcode UISwitch 自定义大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29606221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UISwitch Custom Size
提问by Kashif
I have created a UISwitch
in the Interface Builder. Its default size is 51x31
我UISwitch
在 Interface Builder 中创建了一个。它的默认大小是 51x31
I have put constraints on it to make it smaller size 33x20
我对其进行了限制,使其尺寸更小 33x20
It shows smaller in the Interface Builder but on runtime it does not obey to the size constraints.
它在 Interface Builder 中显示较小,但在运行时它不遵守大小限制。
Elsewhere is it told that UISwitch
is a special control and does not like to obey size constraints. Is it true?
在其他地方被告知这UISwitch
是一个特殊的控件并且不喜欢遵守大小限制。这是真的吗?
Are there any workarounds?
有什么解决方法吗?
回答by Bharath Vankireddy
As simple instead of creating a UISwitch
, create UIButton
and set background image as you want. Here set 2 background images for UIButton
for 2 states. Just toggle the UIButton
between these 2 states
简单而不是创建一个UISwitch
,根据需要创建UIButton
和设置背景图像。这里UIButton
为 2 个状态设置了 2 个背景图像。只需UIButton
在这两种状态之间切换