UITextView宽度大于512不显示文本 [英] UITextView width greater than 512 doesn't show text

查看:98
本文介绍了UITextView宽度大于512不显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我将UITextView扩展到大于512的大小时,代码如下:

Whenever I widen a UITextView to a size greater than 512, with code such as:

textView = [[UITextView alloc] initWithFrame: CGRectMake(0, 0, 513, 1024)];

它不再显示任何文字... 512可以工作,任何尺寸都低于此值,但是任何大于512的东西都会停止显示任何文字。完整代码:

It doesn't display any text anymore... 512 works, any size below that too, but anything greater than 512 and it stops displaying any text. The full code:

- (void)loadView {
    self.navigationItem.hidesBackButton = YES;

    self.view = [[UIView alloc] init];
    self.view.backgroundColor = [UIColor blackColor];

    RDLocalizedStrings * strings = [RDLocalizedStrings defaultLocalizedStrings];

    NSString* message = [strings getStringWithKey: @"noUpdatesAvailableText"];

    CGFloat messageFontSize;

    RDRectCreate(message);

    BOOL iPad = NO;
#ifdef UI_USER_INTERFACE_IDIOM
    iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
#endif
    if (iPad) {
        RDRectWrite(message, 0, 100, 513, 200);
        messageFontSize = 20.0;
    } else {
        RDRectWrite(message, 0,  0, 320, 480);
        messageFontSize = 20.0;
    }

    textView = [[UITextView alloc] initWithFrame: messageRect];
    textView.text = message;
    textView.backgroundColor = [UIColor redColor];
    textView.textAlignment = UITextAlignmentCenter;
    textView.textColor = [UIColor whiteColor];
    textView.font = [UIFont systemFontOfSize: messageFontSize];
    textView.editable = NO;

    [self.view addSubview: textView];
}


推荐答案

似乎 UIViewAutoresizingFlexibleWidth make ipad的 UITextView 隐藏文字。使用调整大小textView.frame = CGRectMake(0,0,768,21)可以修复此问题。

It seem UIViewAutoresizingFlexibleWidth make ipad's UITextView hide text. Resize with textView.frame=CGRectMake(0,0,768,21) can fix this.

这篇关于UITextView宽度大于512不显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆