如何为不同的屏幕尺寸设置按钮框架

时间:2014-04-01 04:47:03

标签: ios objective-c uibutton frame

我有从x原点700左右显示的按钮。它在iPadMini中显示,但是当我在普通iPad上运行应用程序时,它没有显示。

我有四个按钮可以显示。在iPad中我需要显示以下尺寸。

[back_btn setFrame:CGRectMake(10,10,40,40)];

 [save setFrame:CGRectMake(195, 10, 40, 40)];

  [camera setFrame:CGRectMake(385, 10, 40, 40)];

 actionshet setFrame:CGRectMake(575, 10, 40, 40)];


 In iPadMini need to display same buttons in below sizes:




[back_btn setFrame:CGRectMake(30,10,40,40)];

 [save setFrame:CGRectMake(215, 10, 40, 40)];

 [camera setFrame:CGRectMake(405, 10, 40, 40)];

 actionshet setFrame:CGRectMake(605, 10, 40, 40)];

2 个答案:

答案 0 :(得分:2)

设置设备宽度和高度的宏,如 -

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

并给出这样的按钮框架 -

CGRectMake(SCREEN_WIDTH*0.05, SCREEN_HEIGHT*0.05, SCREEN_WIDTH*0.90, SCREEN_HEIGHT*0.08);

答案 1 :(得分:0)

在添加此代码的接口文件中使用autolayout

  [button setFrame:CGRectMake(self.view.frame.origin.x, 10, 40, 40)];