我如何在视图控制器上居中放置内容,以便无论xamarin故事板上使用什么设备大小,都始终居中放置内容? [英] 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?

查看:53
本文介绍了我如何在视图控制器上居中放置内容,以便无论xamarin故事板上使用什么设备大小,都始终居中放置内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用xamarin开发应用程序,因此在启动应用程序时无法使启动屏幕正常工作.我在启动屏幕上使用情节提要.视图设置为通用视图,宽度和高度设置为任意.但是,当我启动该应用程序时,启动屏幕会切断我在视图控制器的通用视图中居中的大部分图片和标签.有人知道我能做什么,以便无论我使用哪种设备(iPhone 5s,6、6plus等),标签始终像在通用视图中一样居中?谢谢

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

推荐答案

如上所述,您需要使用自动布局,该布局可通过xamarin Studio故事板编辑器或Xcode编辑器使用.

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

要使元素在Xcode故事板编辑器上的故事板上居中(我个人更喜欢),只需在其相对于父对象的X和Y位置上添加一个约束即可.

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.

接下来,选择您的UI视图并添加相关的约束,例如,将水平和垂直中心与父级对齐.

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

由于Xamarin.iOS和iOS开发中自动布局是一个如此重要的主题,因此建议您阅读以下内容.

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/

这篇关于我如何在视图控制器上居中放置内容,以便无论xamarin故事板上使用什么设备大小,都始终居中放置内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆