简体   繁体   English

如何调整iphone应用程序的xib视图以适应xcode中的ipad

[英]How to resize the xib view of iphone application to fit to ipad in xcode

I created a simple calculator app in universal mode. 我在通用模式下创建了一个简单的计算器应用 I have two xib one for iphone and other for ipad. 我有两个xib用于iphone,另一个用于ipad。 I created all my view design only in iphone, my ipad xib is blank. 我只在iphone中创建了我的所有视图设计,我的ipad xib是空白的。 Now when I deployed my app for iphone in ipad, it comes in the size of iphone. 现在,当我在ipad中部署我的iphone应用程序时,它的大小与iphone相同。 I have choosen the autoresize option. 我选择了自动调整大小选项。 Will I have to create same view of iphone in ipad xib for the correct display or is there any other way? 我是否必须在ipad xib中创建相同的iphone视图以获得正确的显示效果,还是有其他方法吗? This is how my app currently displays on ipad. 这就是我的应用程序当前在ipad上显示的方式。 I need it in a full screen mode. 我需要全屏模式。 ipad视图

EDIT: This is the sample source code of iphone xib. 编辑:这是iphone xib的示例源代码。 How should I modify this to fit for ipad? 我应该如何修改它以适应ipad?

    <?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
    <data>
        <int key="IBDocument.SystemTarget">1280</int>
        <string key="IBDocument.SystemVersion">10K549</string>
        <string key="IBDocument.InterfaceBuilderVersion">1938</string>
        <string key="IBDocument.AppKitVersion">1038.36</string>
        <string key="IBDocument.HIToolboxVersion">461.00</string>
        <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
            <string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
            <string key="NS.object.0">933</string>
        </object>
        <array key="IBDocument.IntegratedClassDependencies">
            <string>IBUIView</string>
            <string>IBUIBarButtonItem</string>
            <string>IBProxyObject</string>
            <string>IBUIToolbar</string>
            <string>IBUITextField</string>
            <string>IBUITextView</string>
            <string>IBUITableView</string>
            <string>IBUITableViewCell</string>
            <string>IBUIButton</string>
        </array>
        <array key="IBDocument.PluginDependencies">
            <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
        </array>
        <object class="NSMutableDictionary" key="IBDocument.Metadata">
            <string key="NS.key.0">PluginDependencyRecalculationVersion</string>
            <integer value="1" key="NS.object.0"/>
        </object>
        <array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
            <object class="IBProxyObject" id="372490531">
                <string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
                <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
            </object>
            <object class="IBProxyObject" id="843779117">
                <string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
                <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
            </object>
            <object class="IBUIView" id="774585933">
                <reference key="NSNextResponder"/>
                <int key="NSvFlags">274</int>
                <array class="NSMutableArray" key="NSSubviews">
                    <object class="IBUITextField" id="234836822">
                        <reference key="NSNextResponder" ref="774585933"/>
                        <int key="NSvFlags">292</int>
                        <string key="NSFrame">{{12, 48}, {286, 31}}</string>
                        <reference key="NSSuperview" ref="774585933"/>
                        <reference key="NSNextKeyView" ref="1066176330"/>
                        <bool key="IBUIOpaque">NO</bool>
                        <bool key="IBUIClipsSubviews">YES</bool>
                        <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
                        <int key="IBUIContentVerticalAlignment">0</int>
                        <string key="IBUIText">0</string>
                        <int key="IBUIBorderStyle">3</int>
                        <object class="NSColor" key="IBUITextColor">
                            <int key="NSColorSpace">3</int>
                            <bytes key="NSWhite">MAA</bytes>
                            <object class="NSColorSpace" key="NSCustomColorSpace">
                                <int key="NSID">2</int>
                            </object>
                        </object>
                        <int key="IBUITextAlignment">2</int>
                        <bool key="IBUIAdjustsFontSizeToFit">YES</bool>
                        <float key="IBUIMinimumFontSize">17</float>
                        <object class="IBUITextInputTraits" key="IBUITextInputTraits">
                            <int key="IBUIKeyboardType">4</int>
                            <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
                        </object>
                        <object class="IBUIFontDescription" key="IBUIFontDescription" id="1025764138">
                            <int key="type">1</int>
                            <double key="pointSize">14</double>
                        </object>
                        <object class="NSFont" key="IBUIFont" id="891898266">
                            <string key="NSName">Helvetica</string>
                            <double key="NSSize">14</double>
                            <int key="NSfFlags">16</int>
                        </object>
                    </object>
                    <object class="IBUIButton" id="1066176330">
                        <reference key="NSNextResponder" ref="774585933"/>
                        <int key="NSvFlags">292</int>
                        <string key="NSFrame">{{41, 102}, {50, 50}}</string>
                        <reference key="NSSuperview" ref="774585933"/>
                        <reference key="NSNextKeyView" ref="182110945"/>
                        <bool key="IBUIOpaque">NO</bool>
                        <int key="IBUITag">1</int>
                        <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
                        <int key="IBUIContentHorizontalAlignment">0</int>
                        <int key="IBUIContentVerticalAlignment">0</int>
                        <int key="IBUIButtonType">1</int>
                        <string key="IBUINormalTitle">1</string>
                        <object class="NSColor" key="IBUIHighlightedTitleColor" id="899681977">
                            <int key="NSColorSpace">3</int>
                            <bytes key="NSWhite">MQA</bytes>
                        </object>

                              . 
                              .
                              .
                              .

<dictionary class="NSMutableDictionary" key="flattenedProperties">
                <string key="-1.CustomClassName">ViewController</string>
                <string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="-2.CustomClassName">UIResponder</string>
                <string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="10.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="101.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="103.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="104.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="105.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="106.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="11.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="111.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="12.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="13.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="14.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="15.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="16.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="17.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <real value="0.0" key="17.IBUIButtonInspectorSelectedStateConfigurationMetadataKey"/>
                <string key="18.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="19.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="20.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="21.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="22.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="23.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="24.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="25.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="36.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="69.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="78.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="82.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="83.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="9.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="94.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
            </dictionary>
            <dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
            <nil key="activeLocalization"/>
            <dictionary class="NSMutableDictionary" key="localizations"/>
            <nil key="sourceID"/>
            <int key="maxID">125</int>
        </object>
        <object class="IBClassDescriber" key="IBDocument.Classes"/>
        <int key="IBDocument.localizationMode">0</int>
        <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
        <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
        <int key="IBDocument.defaultPropertyAccessControl">3</int>
        <string key="IBCocoaTouchPluginVersion">933</string>
    </data>
</archive>

Right click on XIB. 右键单击XIB。

Choose open as. 选择打开为。

Choose Source code. 选择源代码。

And in it modify following: 并在其中修改以下内容:

 <object class="NSArray" key="dict.values">
    <bool key="EncodedWithXMLCoder">YES</bool>
    <string>{320, 480}</string>
    <string>{480, 320}</string>
    </object>

to: 至:

<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>{768, 1024}</string>
<string>{1024, 768}</string>
</object>

That's it.

I suggest using AutoLayout. 我建议使用AutoLayout。 If you do your view with auto layout for iPhone it will look nearly the same on the iPad, just bigger. 如果您使用iPhone的自动布局进行视图,它在iPad上看起来几乎相同,只是更大。 AutoLayout is pretty easy in XIBs. 在XIB中,AutoLayout非常简单。 The other possibility is to create a separate XIB for the iPad layout. 另一种可能性是为iPad布局创建单独的XIB。 If you do so just have a look at the other answers which describe how to do that easily. 如果你这样做,只需看看其他答案,这些答案描述了如何轻松地做到这一点。

Yes!!! 是!!! You have to create view for iPad also in other Xib file. 您还必须在其他Xib文件中为iPad创建视图。

You need to make two seprate xib and manage all buttons,textfiels and add all these in New Xib... 你需要制作两个seprate xib并管理所有按钮,textfiels并在New Xib中添加所有这些...

Way To Create Ipad Xib from iphone xib.... 从iphone xib创建Ipad Xib的方法....

1)First copy iphone xib and paste just change the name like ~ipad.xib give and add it to the bundle 1)首先复制iphone xib并粘贴只需更改名称~ipad.xib give并将其添加到包中

2)now you have an 2 xib 1 is for iphone and 1 is for ipad. 2)现在你有一个2 xib 1用于iphone,1用于ipad。

3)go to ipad xib right click on in it see open as -> open it in source code and then you have to find 320,480 value search that value in source code and change into 3)转到ipad xib右键单击它看到打开为 - >在源代码中打开它然后你必须找到320,480值搜索源代码中的值并转换为

768,1024... 768,1024 ...

that's it do this way.... 就是这样做......

From Converting iPhone xib to iPad xib? 转换iPhone xib到iPad xib?

Refer Jag's answer..where he States that, 请参考Jag的回答......他说的是,

I was able to narrow it down to a few things, so here are the steps that worked for me: 我能够将其缩小到几个方面,所以这里有适合我的步骤:

1) Make a copy of the iPhone xib file and add it to your project 1)制作iPhone xib文件的副本并将其添加到项目中

2) Right click the file (in xcode) and Open As > Source Code 2)右键单击文件(在xcode中)和Open As> Source Code

3) The 2nd line should look like: 3)第二行应如下所示:

Replace with: 用。。。来代替:

4) Search for "IBCocoaTouchFramework" and Replace all occurrences with "IBIPadFramework" 4)搜索“IBCocoaTouchFramework”并用“IBIPadFramework”替换所有出现的内容

5) Save the file and Open As > Interface Builder - iOS 5)保存文件并打开为>界面生成器 - iOS

The file might still look like a regular iPhone xib, but for me, once I changed the Status Bar to "Black" in the Attributes inspector the rest of the xib just kind of "snapped" into an iPad xib 该文件可能仍然看起来像普通的iPhone xib,但对我来说,一旦我在属性检查器中将状态栏更改为“黑色”,其余的xib就会被“抢购”到iPad xib中

EDIT : You can also do in this way==> convert iphone App to IPad 编辑 :您也可以这样做==> 将iphone应用程序转换为iPad

1) Select the Universal option. 1)选择通用选项。

2) Transfer code from the existing iPhone project to the new project. 2)将代码从现有的iPhone项目转移到新项目。

3) NOW,Make the xib files for iPad, and make the connections (IBOutlets). 3)现在,为iPad制作xib文件,并进行连接(IBOutlets)。

Wherever you need platform specific features (eg. Popover, Split ViewController etc for iPad), put an IF statement to handle the device specific features. 无论您需要特定于平台的功能(例如,用于iPad的Popover,Split ViewController等),请使用IF语句来处理设备特定功能。

在iPhone xib文件中,将目标从iOS.CocoaTouch更改为iOS.CocoaTouch.iPad,现在如果在界面构建器中打开文件,您将看到iPad的设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM