【问题标题】:change a buttons frame size when another button tapped Xcode当另一个按钮点击 Xcode 时更改按钮的框架大小
【发布时间】:2015-04-30 19:25:06
【问题描述】:

我有一个应用程序,我希望在点击另一个按钮时在不同设备上更改按钮的框架大小。当我点击 iPad 上的按钮时,另一个按钮的框架大小会改变,并在点击另一个按钮时变回。但是,在 iPhone 上不会发生这种情况。

这是 iphone 上的原始尺寸 (568高度) button.frame = CGRectMake(18,456,126,13);

其他高度 button.frame = CGRectMake(18,370,126,13);

这是 iPad 上的尺寸

button.frame = CGRectMake(47,577,251,26);

这是在点击另一个按钮时更改按钮大小的代码

-(IBAction)changeSize:(id)sender{
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)     {

    int height = [UIScreen mainScreen].bounds.size.height;

    if (height == 568) {
self.button.frame = CGRectMake(18,339,100,13);

 }
 else {
 self.button.frame = CGRectMake(18,279,100,13);
 }

}
else if([[UIDevice currentDevice] userInterfaceIdiom] ==    UIUserInterfaceIdiomPad){
 self.button.frame = CGRectMake(47,603,200,26);
 }

就像我说的那样,在 iPad 上更改按钮大小效果很好,但在 iPhone 上却不行。 有什么建议吗?

谢谢

【问题讨论】:

    标签: uibutton xcode6 cgrectmake


    【解决方案1】:

    所以我为 iPhone 而不是 iPad 启用了自动布局。一旦我在 iPhone 上禁用它,它就可以完美运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      相关资源
      最近更新 更多