iOS 中 UI 元素的边距和填充
到目前为止我已经为Android开发了。在那里,您可以为几乎每个 UI 元素设置layoutMargin 和 padding(当您在 xml 文件中描述 UI 时)。
这是如何在 iOS 中的 UIViews 代码中完成的(如果有通用命令)?
总氮
I have so far developed for Android. There, you can set layoutMargin and padding for almost every UI element (when you describe UI in xml file).
How is this done in code for UIViews in iOS (if there is a common command)?
Tnx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
iOS 采用不同的方法来放置控件 - 没有布局引擎,您可以为所有控件指定绝对坐标和大小。有点像 Android 中的
AbsoluteLayout
。因此,边距和填充的概念并不真正适用 - 相邻控件之间的间隙完全取决于您,它们不是由系统计算的。尺寸相同。
这使得实现“使该控件的大小达到其文本所需的大小”的场景变得更加困难。但是,您不会遇到流氓线绕行。
编辑:
AbsoluteLayout
如今已被弃用。iOS employs a different approach to control placement - there's no layouting engine, you specify absolute coordinates and size for all controls. Kinda like the
AbsoluteLayout
in Android.So the concepts of margin and padding don't really apply - the gaps between adjacent controls are completely up to you, they're not computed by the system. Same for sizes.
This makes it more difficult to implement the scenario of "make this control as large as it needs to be for its text". However, you won't run into rogue line wraps.
EDIT:
AbsoluteLayout
is deprecated these days.您可以在代码中或使用 Interface Builder(或 Xcode 4 中的 .xib 编辑器)布置 UI 元素。您将为视图指定实际坐标,但也可以为每个视图指定调整大小行为。因此,您可以说特定视图应始终保持相同的大小并保持水平居中,或者它应该保持其大小并保持左侧边距,或者它应该拉伸以保持左右边距等。在 IB 中查找“autosizing”部分,或者在代码中设置任何视图的 autoresizingMask 属性。
You lay out your UI elements either in code or using Interface Builder (or the .xib editor in Xcode 4). You'll specify actual coordinates for your views, but you can also specify the resizing behavior for each view. So, you can say that a particular view should always keep the same size and remain horizontally centered, or that it should keep it's size and maintain the margin on the left, or that it should stretch to keep both left and right margins, etc. Look for the "autosizing" section in IB, or set the
autoresizingMask
property of any view in code.在ios中可以使用Interface Builder进行设计。你仍然可以使用 xml,但没有人使用它。
In ios you can use Interface Builder for design. You can still use xml, but no one use this.