[英]ios create 'readmore'. Let superview be dependent of subview
ios中的gaaah设计让我头疼! 因此,请帮帮我,Maby向我解释如何想出解决方案。
我有:
我想要:
按阅读更多的btn,以便UITextField获得其实际大小。 没问题,我可以通过编程获取contentSize来做到这一点。 它可以工作,但是它的ofc溢出了tableHeader
所以我想,很好。 然后,我要做的就是将tableHeader设置为UITextField的“新”计算高度的大小+ 2个UIImageViews的高度。
但是不。 它只会调整为在故事板上安装的现有高度。 换句话说,它做一个或另一个。 使用自动布局会完全破坏但不会给我关于约束的任何错误。
这似乎很容易让我感到很愚蠢哈哈
这就是我的代码
- (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];
请指导我怎么想
- (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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.