简体   繁体   English

自动布局按钮位置

[英]auto layout button position

I have a simple problem with the new Auto Layout feature. 我对新的自动版式功能有一个简单的问题。 I have an app that wil work on the iphone 4, 4s and 5. I need to position a button on the screen and the button needs to be 302 pixels from the buttom at 4 inch screen and 282 pixels at 3.5 (both speaking at retina resolution). 我有一个可以在iphone 4、4s和5上运行的应用程序。我需要在屏幕上放置一个按钮,并且该按钮需要在4英寸屏幕上距臀部302像素,在3.5英寸处需要282像素(都在视网膜上解析度)。 How do I accomplish this? 我该如何完成?

I found a cupple of tutorials but none of them seems to be covering this what I am after. 我找到了很多教程,但似乎都没有涵盖我所追求的内容。 Any ideas? 有任何想法吗?

if you're building for less than iOS 6.0 the app will crash if you use autolayout. 如果您的版本低于iOS 6.0,则使用自动版式时该应用将崩溃。 It will only work on iOS 6. 它仅适用于iOS 6。

That said, how I've dealt with different screen heights while supporting older versions of iOS: 也就是说,在支持旧版iOS的同时如何处理不同的屏幕高度:

You make a macro 你做一个宏

#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

and can check like this. 并可以像这样检查

if( IS_IPHONE_5 )
{ 
    //position the button 302 px from bottom of the screen
}
else
{ 
    //position the button 282 pixels from the bottom of the screen
}

this question helped me 这个问题帮助了我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM