2013-05-01 107 views
1

gaaah在ios中設計讓我頭疼! 所以,請幫助我,並向我解釋如何應該考慮嘗試提出解決方案。ios創建'readmore'。讓超級視圖取決於子視圖

我:

UITableView with its header

  • 正如你所看到的UITextField有其框架正在故事板設置成比它的實際內容更小。
  • prototypecell上面的所有東西都在編程設置爲tableHeader的UIView中。

我想:

按讀更多BTN從而使得到的UITextField它的實際大小。沒問題,我可以通過以編程方式獲取contentSize來做到這一點。它可以工作,但它會溢出桌面頭部

所以我認爲,很好。然後,我所要做的就是將tableHeader設置爲UITextField的「新」計算高度的大小+ 2個UIImageView的高度。

但沒有。它只調整到故事板設置的現有高度。換句話說,它是一個或另一個。 並使用自動佈局它完全破壞,但不給我任何約束的錯誤。

這似乎很容易至極讓我覺得很愚蠢哈哈

這是我有我的代碼

- (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

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]; 
    } 
+0

dynamicHeightCalculatedAfterTextSize?我如何設置這個取決於db和textSize的內容? 我忘了說我有一個自己的UIView中的textView需要與textView一起調整大小。我試圖做 '[self.textSuperView setFrame:CGRectMake(self.textView.frame.origin.x,self.textView.frame.origin.y,textSize.width,textSize.height)];' 但是沒有任何東西發生。 – Pedroinpeace 2013-05-01 10:22:38

+0

假設HeaderView的高度爲100(不包含)textview。然後dynamicHeightCalculatedAfterTextSize將-dynamicHeightCalculatedAfterTextSize = 100 + textSize.height – 2013-05-01 10:25:43

+0

更改您的UIView的超類到UITableViewHeaderFooterView – 2013-05-01 10:30:08

相關問題