单击单元格上的 seeMoreBtn 后,我想扩大单元格大小。
标签和单元格的长度不同,但它们是标签大小的约束。
当一个状态太大时,我添加了一个seeMoreBtn,点击查看更多后剩余的文本会显示在下面,然后如何增加标签和单元格大小。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSString *text = [items objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(300.0f, 150.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:constraint lineBreakMode:NSLineBreakByCharWrapping];
CGFloat height1 = MAX(size.height, 44.0f);
return height1 + (40.0f);
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"Cell-%d",indexPath.row];
cell=[tv dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
int lbltag = 1000;
label=[[UILabel alloc]initWithFrame:CGRectZero];
[label setLineBreakMode:NSLineBreakByWordWrapping];
[label setMinimumScaleFactor:14.0f];
[label setNumberOfLines:0];
[label setFont:[UIFont systemFontOfSize:14.0f]];
NSString *text = [items objectAtIndex:[indexPath row]];
[label setText:text];
label.tag = lbltag;
[cell addSubview:label];
CGSize constraint1=CGSizeMake(300.0f, 150.0f);
CGSize size1=[text sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:constraint1 lineBreakMode:NSLineBreakByWordWrapping];
[label setFrame:CGRectMake(10.0f, 10.0f, 300.0f, MAX(size1.height, 44.0f))];
int countText=text.length;
if (countText>=350) {
seeMoreBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[seeMoreBtn setTitle:@"See More" forState:UIControlStateNormal];
seeMoreBtn.frame=CGRectMake(220.0f, MAX(size1.height, 44.0f)-10, 80.0f, 20.0f);
seeMoreBtn.tag=indexPath.row ;
[seeMoreBtn addTarget:self action:@selector(increaseSize:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:seeMoreBtn];
}
return cell;
}
-(void)increaseSize:(UIButton *)sender{
//What to write here that can adjust the label and cell size
}