我的UIButton的位置在所有模拟器中都有所不同
我在一个项目下。在我使用代码(不通过故事板)在我的viewcontroller底部创建了一个uibutton。但是当我运行我的应用程序时,我的uibutton放置在不同的位置。例如在iphone 5,6模拟器中在4s,ipad模拟器我的uibutton是不可见的。我也检查我自己的设备(iphone 6),在那也是我的uibutton无法看到。
需要
我使用下面的代码创建和放置我的按钮位置。但它不适合在一个位置。
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
设置自动布局
链接1
链接2
链接3
当然这会对你有所帮助!