我在一个项目下。我使用代码(不是通过故事板)在视图控制器的底部创建了一个 uibutton。但是当我运行我的应用程序时,我的 uibutton 放置在不同的位置。例如在 iphone 5,6 模拟器中某个位置。在 4s 中,ipad 模拟器我的 uibutton 不可见。我还检查了我自己的设备(iphone 6),因为我的 uibutton 也看不到。
Needed
我使用下面的代码来创建和放置按钮位置。但它不适合一个位置。
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
请为这个问题提供一些代码解决方案。
根据有关您问题的所有评论。您需要为您的UIButon
.仅使用centre x,centre y
因为这将有助于在所有设备中查看您的布局。您的问题已经有了解决方案。请参阅下面的链接来设置自动布局UIButton
Link 1
Link 2
Link 3
当然这会对你有帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)