gpt4 book ai didi

ios 创建 'readmore' 。让 superview 依赖于 subview

转载 作者:行者123 更新时间:2023-11-29 13:14:02 25 4
gpt4 key购买 nike

gaaah 在 ios 中设计让我很头疼!!所以,请帮助我,也许可以向我解释在尝试提出解决方案时应该如何思考。

我有:

UITableView with its header

  • 如您所见,UITextField 的框架在 Storyboard中设置为小于其实际内容。
  • prototypecell 之上的所有内容都在一个 UIView 中,该 UIView 以编程方式设置为 tableHeader。

我想:

按阅读更多按钮,以便 UITextField 获得其实际大小。没问题,我可以通过编程方式获取 contentSize 来做到这一点。它有效,但它溢出了 tableHeader

所以我想,很好。然后我所要做的就是将 tableHeader 设置为 UITextField 的"new"计算高度的大小 + 2 个 UIImageView 的高度。

但是没有。它只会调整到 Storyboard中设置的现有高度。换句话说,它做一个或另一个。使用自动布局它完全中断但没有给我关于约束的任何错误。

这看起来很简单,让我觉得很愚蠢哈哈

这就是我的代码

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

请指导我如何思考

最佳答案

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

关于ios 创建 'readmore' 。让 superview 依赖于 subview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16313937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com