How can i center the content on a view controller

2019-09-10 12:07发布

问题:

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/