UITextView宽度大于512不显示文本

时间:2010-07-09 13:15:32

标签: ipad uitextview

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

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

它不再显示任何文本... 512工作,任何大小也低于此,但任何大于512,它停止显示任何文本。完整代码:

- (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];
}

1 个答案:

答案 0 :(得分:3)

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