Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView width greater than 512 doesn't show text

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

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

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];
}
like image 627
Nick Avatar asked Jul 09 '10 13:07

Nick


1 Answers

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

like image 115
Kai Avatar answered Oct 05 '22 03:10

Kai