【问题标题】:UITextView width greater than 512 doesn't show textUITextView 宽度大于 512 不显示文字
【发布时间】:2011-03-13 21:02:47
【问题描述】:

每当我将 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];
}

【问题讨论】:

标签: ipad uitextview


【解决方案1】:

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

【讨论】:

  • 如果当前帧已经正确,只需指定textView.frame = textView.frame; 似乎就可以了。
猜你喜欢
  • 1970-01-01
  • 2013-01-04
  • 1970-01-01
  • 2011-05-03
  • 2015-06-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-27
相关资源
最近更新 更多