【问题标题】:Can you establish a button in IB and move it programmatically?您可以在 IB 中建立一个按钮并以编程方式移动它吗?
【发布时间】:2010-09-23 19:53:03
【问题描述】:

我在 IB 中设置了一个按钮。我设置了一个 IBOutlet 并将屏幕上的对象链接到它。有没有办法以编程方式更改按钮的位置和/或大小?我知道您可以更改标题和一些内容,但我不知道如何更改它的位置或大小。

谢谢。

【问题讨论】:

标签: iphone objective-c xcode ipad


【解决方案1】:

您可以更改按钮(或任何 UIView)的frame

CGRect frame = [button frame];
frame.origin.x += 100;  // change the location
frame.size.width += 100;  // change the size
[button setFrame:frame];

【讨论】:

  • 谢谢先生们。我相信您已经为我提供了答案。
【解决方案2】:

您只需为其创建一个新框架,即myButton.frame = CGRectMake(0,0,123,412);,它就会移动到该新框架。 CGRectMake 的顺序是(原点 x,原点 y,宽度,高度)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    • 2015-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多