【发布时间】:2017-11-25 08:36:09
【问题描述】:
我制作了一个可展开和可折叠的表格视图。如果点击部分,它们会展开,如果它们已经展开,它们会折叠。
对于部分,我已经查看了。在 UIView 内部,有标签,标签上有点击手势。它工作正常。现在,问题是标签和视图的大小是固定的,但实际上如果标签内的文本超过标签的高度,我希望标签扩大。但是,即使几次努力我也无法实现.请检查以下代码并给出一些进一步的方向。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *sectionView=[[UIView alloc]initWithFrame:CGRectMake(30, 5,self.expandableTableView.frame.size.width-30,40)];
sectionView.tag=section;
UILabel *viewLabel=[[UILabel alloc]initWithFrame:CGRectMake(10,5,sectionView.frame.size.width-60, 40)];
imgView=[[UIImageView alloc]initWithFrame:CGRectMake(viewLabel.frame.size.width+10,10,30, 30)];
imgView.image = [UIImage imageNamed:@"down.png"];
viewLabel.backgroundColor=[UIColor clearColor];
viewLabel.textColor=[UIColor darkTextColor];
viewLabel.font=[UIFont systemFontOfSize:15];
viewLabel.text=[NSString stringWithFormat:@"List of %@",[_sectionArray objectAtIndex:section]];
[sectionView addSubview:viewLabel];
[sectionView addSubview:imgView];
/********** Add a border with Section view *******************/
sectionView.layer.borderWidth = 1;
sectionView.layer.borderColor = [[UIColor grayColor] CGColor];
sectionView.layer.cornerRadius = 5;
/********** Add UITapGestureRecognizer to SectionView **************/
UITapGestureRecognizer *headerTapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sectionHeaderTapped:)];
[sectionView addGestureRecognizer:headerTapped];
return sectionView;
}
任何帮助将不胜感激。在此先感谢
【问题讨论】:
标签: ios objective-c uitableview header