通用应用程序上 .XIB 中的 UIView 始终报告 iPhone UI 大小
我正在尝试以尽可能少的工作量将 iPhone 应用程序移植到 iPad,但我陷入了最后一点。
我有一个位于屏幕底部的自定义 UI 元素。 UI 元素只是 UIView 的子类,具有一些委托方法和自定义绘图以满足我的客户需求。 UIView 包含多个等间隔的 UIButton 对象。
我的问题是如何让这些以编程方式创建的 UIButton 保持居中?有一个中央 .xib 文件,其中包含 CustomNavBar 子类的 UIView。在 CustomNavBar 类中,我尝试执行以下操作:
self.frame.size...
或
self.bounds.size...
或
CGRect rect = [[UIScreen mainScreen]bounds];
rect.origin.size...
但所有返回都是标准 iPhone 尺寸。我已经在 .XIB 文件中包含的其他对象上设置了所有自动调整大小,但我无法弄清楚如何处理以编程方式创建 UI 方面的实例。
希望你能帮忙。
I am trying to port an iPhone app to iPad with as little work as possible and I am stuck on one last point.
I have a custom UI element that sits along the bottom of the screen. The UI element is simply a subclass of UIView with some delegate methods and custom drawing for my clients needs. The UIView contains several UIButton objects spaced out equally.
My question is how to get these programmatically created UIButtons to remain centred? There is a central .xib file that contains a UIView of subclass CustomNavBar. Within the CustomNavBar class I have tried to do the following:
self.frame.size...
or
self.bounds.size...
or
CGRect rect = [[UIScreen mainScreen]bounds];
rect.origin.size...
but all of the returns are the standard iPhone sizes. I have set all of the autoresizing on the other objects contained within the .XIB file but I am unable to fathom out what to do with the instance where the UI aspect is created programmatically.
Hope you can help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用适用于 iPad 的备用 xib,因此它具有默认的 iPad 尺寸。如果您的 xib 是为 iPhone 设备系列创建的,则它无法很好地集成在 iPad 上。
例如,使用此代码获取 xib 的 iPad 版本。您还可以创建一个宏(或函数),它采用 xib 名称并返回 iPhone xib 名称或 iPad xib 名称(如果当前设备是 iPad,则附加 _iPad)。
You can use an alternate xib for iPad, so it has the default iPad size. If your xib is created for iPhone device family, it won't be well integrated on iPad.
Use this code to get the iPad version of the xib for example. You can also create a macro (or function) that take the xib name and return either the iPhone xib name, or the iPad xib name (append the _iPad if the current device is an iPad).