我的 UIButton 的位置在所有模拟器中都不同

Position of my UIButton are varying for in all simulator

我在 project.In 之下,我使用代码(不是通过故事板)在我的 viewcontroller 底部创建了一个 uibutton。但是当我 运行 我的应用程序时,我的 uibutton 是在 iphone 5,6 模拟器中放置不同的 positions.for 示例在一些 position.In 4s,ipad 模拟器中我的 uibutton 是 unvisible.Also 我用我自己的设备检查( iphone 6) ,因为我的 uibutton 也看不到。

需要

我使用下面的代码来创建和放置我的按钮position.but它不适合一个位置。

 CGFloat buttonSize = 40;

    UIButton * disButton = [[UIButton alloc] init];
    disButton.backgroundColor = [UIColor redColor];
    UIImage *btnImage = [UIImage imageNamed:@"23"];
    [disButton setImage:btnImage forState:UIControlStateNormal];
    disButton.frame = CGRectMake(150, 523, 40, 40);
    [overlayView addSubview:disButton];
    [disButton addTarget:self action:@selector(dismissPopUpViewController)
        forControlEvents:UIControlEventTouchUpInside];

在我的代码中,我用来在这一行中放置位置:

disButton.frame = CGRectMake(150, 523, 40, 40);

=> x-position = 150

=> Y-position = 523

请为这个问题提供一些代码解决方案。

根据所有关于您的 question.You 的评论需要为您的 UIButon 设置约束。仅使用 centre x,centre y 因为这将有助于在所有设备中查看您的布局。您的 problem.see 已经有一个解决方案,这些链接用于为 UIButton

设置自动布局

Link 1

Link 2

Link 3

当然这对你有帮助!