xcode 你能在IB中建立一个按钮并以编程方式移动它吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3782039/
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
Can you establish a button in IB and move it programmatically?
提问by emachine
I have a button set up in IB. I have an IBOutlet set up and the onscreen object linked to it. Is there a way to programmatically change that buttons position and/or size? I know you can change the title and some things but I don't see how to change it's position or size.
我在 IB 中设置了一个按钮。我有一个 IBOutlet 设置和链接到它的屏幕对象。有没有办法以编程方式更改按钮位置和/或大小?我知道您可以更改标题和某些内容,但我不知道如何更改它的位置或大小。
Thank You.
谢谢你。
回答by cobbal
回答by MishieMoo
You simply create a new frame for it i.e. myButton.frame = CGRectMake(0,0,123,412);
and it moves to that new frame. The order for CGRectMake is (origin x, origin y, width, height).
您只需为它创建一个新框架,即myButton.frame = CGRectMake(0,0,123,412);
它会移动到该新框架。CGRectMake 的顺序是(原点 x,原点 y,宽度,高度)。