【问题标题】:Autosizing a UIView that contains a UITextView自动调整包含 UITextView 的 UIView
【发布时间】:2013-10-11 02:06:05
【问题描述】:

我在表格视图之前有一个 UITableViewController 和一个 UIView。 UIView (IBOutlet UIView *templateDescriptionView) 中有一个 UITextView (IBOutlet UITextView *templateDescription)。它看起来像这样:

UITextView 可以有可变数量的文本。我正在尝试以编程方式调整 UITextView 和 UIView 的大小以弥补这一点,但它没有按预期工作。

-(void) viewDidLoad
{
    [templateDescription sizeToFit];

    CGRect frame = templateDescription.frame;
    frame.size.height = templateDescription.contentSize.height;
    templateDescription.frame = frame;

    CGRect viewFrame =  templateDescriptionView.frame;
    viewFrame.size.height = templateDescription.contentSize.height + 40; // 40 for padding
    templateDescriptionView.frame = viewFrame;
}

问题是,当一切渲染时,UIView 部分位于 UITableView 之上。它调整大小,但没有调整到适当的高度。我究竟做错了什么?这是 Xcode 5,iOS7。

【问题讨论】:

  • 你为什么要调整 UITextView 的大小??是不是默认可以滚动的??
  • 我希望它填满该区域而无需滚动。

标签: iphone ios uitextview


【解决方案1】:

恐怕我误解了你的意思。但是 UITableViewController 是用来控制一个 UITableView 的。 UITableViewController 控制 UIView 是否运行良好?也许你把一个 UIView 放到 tableView 的 HeaderInSection 中。在iOS7中,self.automaticallyAdjustsScrollViewInsets = NO;可以用来去除scrollview中的空格插入。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2019-07-29
    • 1970-01-01
    • 2020-07-20
    • 2014-01-18
    相关资源
    最近更新 更多