ios创建'readmore'。让superview依赖于子视图

时间:2013-05-01 06:49:53

标签: ios resize subview superview tableheader

在ios中设计的gaaah让我很头疼!! 所以,请帮助我,maby向我解释一个人应该如何考虑尝试提出解决方案。

我有:

UITableView with its header

  • 正如您所看到的,UITextField在故事板中设置的框架小于其实际内容。
  • 原型单元格上方的所有内容都在以编程方式设置为tableHeader的UIView内。

我想:

按下更多btn,以便UITextField获得其实际大小。没问题,我可以通过编程方式获取contentSize。它有效,但它溢出了tableHeader

所以我想,好。然后我要做的就是将tableHeader设置为UITextField的“新”计算高度的大小+ 2个UIImageViews的高度。

但是不。它只调整到故事板中设置的现有高度。换句话说,它做了一个或另一个。 并且使用autolayout它完全打破但没有给我任何关于约束的错误。

这看起来很容易让我感到如此愚蠢哈哈

这就是我的代码

- (IBAction)toggleReadMore:(id)sender{

_toggleReadMoreBtn.hidden = YES;

CGRect textFrame = _cityDescription.frame;

_cityDescription.frame = textFrame;

CGRect tableHeaderViewFrame = CGRectMake(0, 0, self.tableView.tableHeaderView.frame.size.width, _cityDescription.contentSize.height + 218.0f ); //textFrame.size.height
   self.tableView.tableHeaderView.frame = tableHeaderViewFrame;

    textFrame.size.height = _cityDescription.contentSize.height;
    [self.tableView setTableHeaderView:self.viewForTableHeader];
请告诉我如何思考

1 个答案:

答案 0 :(得分:1)

ScrrenShot indicating constraints

 - (IBAction)readMoreBtnClicked:(UIButton *)sender
     {
         NSLog(@"Read more Btn Clicked");

         NSString *stringToBeDisplayed = @"Any Text Here";

         CGSize textSize=[stringToBeDisplayed sizeWithFont:[UIFont systemFontOfSize:30]
                                        constrainedToSize:CGSizeMake(270, 500)
                                            lineBreakMode:NSLineBreakByWordWrapping];

         NSLog(@"textSize = %@",NSStringFromCGSize(textSize));

        [self.textView setFrame:CGRectMake(self.textView.frame.origin.x,self.textView.frame.origin.y, textSize.width, textSize.height)];

        NSLog(@"self.textView.frame = %@",NSStringFromCGRect(self.textView.frame));

        [self.textView setText:stringToBeDisplayed];
        [self.headerView setFrame:CGRectMake(self.headerView.frame.origin.x,self.headerView.frame.origin.y, 320, dynamicHeightCalculatedAfterTextSize)];

        [self.tableView reloadData];
     }
相关问题