【问题标题】:How to set the height in the code of the UITextView created with Xcode storyboard如何在使用 Xcode 故事板创建的 UITextView 的代码中设置高度
【发布时间】:2013-02-21 13:47:02
【问题描述】:

在 Xcode for iPhone(版本 4.6 (4H127) 中运行 UITextView 对象时,我无法设置高度。 我使用 MainStoryboard_iPhone.storyboard 创建 UITextView。

这个我试过了,没有效果:

UITextView *textMultiLine1;
[textMultiLine1 setContentSize:CGSizeMake(320, 320)];

感谢您的回答,我是 Xcode 的初学者。

【问题讨论】:

    标签: xcode storyboard uitextview


    【解决方案1】:

    你首先需要在你的头文件中创建一个 Outlet:

    IBOutlet UITextView *textMultiLine1;
    

    然后你需要在 StoryBoard 中连接它:

    那么你必须设置它的框架:

    textMultiline1.frame = CGRectMake(originX, originY, width, height);
    

    或者,如果你只想改变它的高度:

    float newHeight = 200.0;
    
    CGRect textViewFrame = textMultiline1.frame;
    textMultiline1.frame = CGRectMake(textViewFrame.origin.x, textViewFrame.origin.y, textViewFrame.size.width, newHeight);
    

    设置内容大小只会改变内部 TextView 区域,导致滚动更长(或更短,取决于您设置的值)

    【讨论】:

    • 感谢您的快速回答。
    • 当我使用您的示例时,我得到 (CGRect) origin=(x=0,y=0) size=(width=0, height=0) 。在我的头文件中,我只能这样写:@property (weak, nonatomic) IBOutlet UITextView *textMultiLine1;
    • 您确定您已将插座连接到 Interface Builder 中的 TextView 吗?
    • 是的,它已连接。我如何向您发送屏幕截图等?
    • 我发现了问题。 “UITextView”对象在故事板中设置为“使用自动布局”。
    猜你喜欢
    • 1970-01-01
    • 2016-09-18
    • 1970-01-01
    • 2014-11-14
    • 2014-09-29
    • 1970-01-01
    • 1970-01-01
    • 2012-02-17
    • 2016-01-12
    相关资源
    最近更新 更多