【问题标题】:How to change the size of text fields when turned to landscape Xcode转向横向Xcode时如何更改文本字段的大小
【发布时间】:2012-06-17 23:36:36
【问题描述】:

我正在创建一个 iPad 应用程序,它是一个主要包含文本框的表单。当 iPad 为纵向时,它会在两列中垂直显示文本字段。当我转动 iPad 横向时,它仍然以完全相同的方式显示文本字段,只是屏幕右侧有空地。我的问题是 - 当文本框变成横向时,如何增加标签和文本字段的大小以填充空白空间?

【问题讨论】:

    标签: ios xcode cocoa-touch uikit interface-builder


    【解决方案1】:

    确保正确设置文本字段的支柱和弹簧! 以下是您应该在 Interface Builder 中设置的内容:

    如果您使用代码执行此操作,则代码如下:

    myTextField.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin
    

    无论哪种方式,您都必须将其设置为表单中的每个文本字段。

    【讨论】:

    • 谢谢,帮助了我。我从来没有真正注意到这个自动调整功能:-)
    【解决方案2】:

    如果您使用的是 XIB,请使用检查器确保您将布局指南设置为固定,以便文本字段的宽度与 XIB 边缘的长度保持恒定 - 从而在界面方向更改时拉伸文本字段.

    如果您在代码中布局视图,请在 UIViewController 子类中实现以下内容:

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    
        [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    
        if( UIInterfaceOrientationIsPortrait(toInterfaceOrientation) ){
            // Adjust your text field...
        } else if( UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ){
            // Adjust your text field...
        }
    }
    

    【讨论】:

    • 另外,你知道如何让标签和文本字段在变成横向时浮动(移动到不同的位置)吗?
    • 您始终可以手动为标签和文本字段设置新的原点坐标。如果可能,请使用答案stackoverflow.com/questions/5169517 中所述的自动调整大小掩码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-12
    • 1970-01-01
    • 2018-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-08
    相关资源
    最近更新 更多