I have made a expandable and collapsable tableview .Where if sections are tapped they expand and if they are already expanded they collapse.
For section thing,I have taken a view .Inside the UIView, there is label and on label there is tap gesture.It is working fine. Now, the problem is that the size of label and view is fix, but actually I want the label to expand if the text inside the label is more than the height of the label.But , I ma no able to achieve it even several efforts.Kindly check the following code and give some directions to move further.
- (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;
}
Any help would be appreciated .Thanks in advance