How can i center the content on a view controller so that it is always centered no matter what device size is used in xamarin storyboard?

半世苍凉 提交于 2019-12-13 03:37:33

问题


Im developing an app in xamarin and I am having trouble getting the Launch Screen to work properly for when i boot up the app. I am using storyboard for the launch screen. The view is set at generic and the width and height are set to any. However when I start the app the launch screen cuts off the majority of my picture and labels that i have centered in the generic view on the view controller. Does anyone know what i can do so that no matter what device I use (iPhone 5s, 6, 6plus, etc.), the labels are always centered like in the generic view? Thanks


回答1:


As @pnavk as mentioned, you need to use Auto layout, which is available both through the xamarin studio storyboard editor or the Xcode editor.

To centre a element on a storyboard on the Xcode storyboard editor(as I personally prefer) simply add a constraint on their X and Y position relative to their parent.

Next, select your UI views and add relevant constraints for example, align horizontal and vertical centres to the parent.

As Auto Layout is such an important topic in Xamarin.iOS and iOS development in general, I suggest you read the following.

https://developer.xamarin.com/guides/ios/user_interface/designer/designer_auto_layout/ https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/



来源:https://stackoverflow.com/questions/38666181/how-can-i-center-the-content-on-a-view-controller-so-that-it-is-always-centered

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!