Objective-C 对象放置 iPad
我有一个扩展 UIViewController 的 GUI 类。
在其函数 viewDidLoad
中,我希望有一个 UITextField
实例。我希望该实例不与简单的 CGRect 对齐,设置其偏移量以及宽度和高度,但我希望动态调整它的大小,使其填充屏幕的整个宽度,从顶部、左侧和底部偏移 5px每个右侧,高度为 20px。这是怎么做到的?
无论设备方向如何,它都应该保持“相对绝对”定位,支持所有方向。
也许有类似 LayoutManager 的东西,例如 Java 中的 GridBagLayout?
I have a GUI class extending UIViewController.
In its function viewDidLoad
, I would like to have a UITextField
instance. I would like that instance not aligned as a simple CGRect, setting its offset and width and height, but I want it rather to be resized dynamically, making it fill the whole width of the screen, with an offset of 5px from top, left and right each and a height of 20px. How is that done?
It should maintain the "relatively-absolute" positioning regardless of the device orientation, all orientations being supported.
Maybe there's something like a LayoutManager, as, for instance, GridBagLayout in Java?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您想要设置视图的
autoresizingMask
属性。这一切也可以通过 Interface Builder 完成。甚至还有一个小动画显示视图如何在 Interface Builder 中调整大小。
You want to set the
autoresizingMask
property of the view.This can all be done from Interface Builder as well. There's even a little animation showing how the view will resize in Interface Builder.
请记住,UIViewController 本身并不显示,但它管理视图对象的层次结构。您可以在 -viewDidLoad 中创建文本字段,但需要将其添加到视图控制器的视图中才能看到它。您可以这样做:
当然,如果您稍后需要再次引用该字段,您还需要将指向它的指针存储在属性或 ivar 中。
Remember that a UIViewController itself isn't displayed, but it manages a hierarchy of view objects. You can create the text field in -viewDidLoad, but it needs to be added to the view controller's view before you can see it. You'd do something like this:
Of course, if you need to refer to that field again later, you'll also want to stash a pointer to it in a property or ivar.
操作系统中没有内置任何此类内容。我见过几个版本的类似你所问的内容,包括我自己的版本,位于 GitHub
There is nothing as such built into the OS. I have seen a couple of versions of something like what you're asking, including my own which is up on GitHub