tableviewcontroller
我通过拖放在 IB 中的顶部添加了一个 UIView,然后我已分配IBoutlet
给它UIView
。
问题是我有一个 uilabel 动态改变它的大小,所以如果 uilabel 很短,我想让 tableview 更接近,否则 tableview 不应该那么接近,所以我可以显示一个很长的标签。
所以我尝试改变uiviewuiview
顶部的框架,tableview
改变它的框架大小,但 tableview 在那里保持稳定。
当我使框架尺寸高度更大时,我想使uitableview
下降UIview
if ([[self agenda] getMeetingTime] != nil) {
descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, dateLabel.frame.origin.y + dateLabel.bounds.size.height+15, self.view.frame.size.width-75, 150)];
descriptionLabel.textColor =[UIColor colorWithRed:96/256.0 green:96/256.0 blue:96/256.0 alpha:1.0];
descriptionLabel.font = [UIFont fontWithName:@"GillSans" size:15.0f];
descriptionLabel.text =[[self agenda] getMeetingTime];
descriptionLabel.backgroundColor = [UIColor clearColor];
descriptionLabel.numberOfLines=0;
descriptionLabel.tag=PopulateTag;
//Calculate the expected size based on the font and linebreak mode of your label
CGSize maximumLabelSize = CGSizeMake(709,999);
CGSize expectedLabelSize = [descriptionLabel.text sizeWithFont:descriptionLabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:descriptionLabel.lineBreakMode];
//adjust the label the the new height.
CGRect newFrame = descriptionLabel.frame;
newFrame.size.height = expectedLabelSize.height;
descriptionLabel.frame=newFrame;
if ( expectedLabelSize.height>70) {
self.upperView.frame = CGRectMake(0, 0, self.upperView.frame.size.width, self.upperView.frame.size.height+expectedLabelSize.height+20);
}
else
{
self.upperView.frame = CGRectMake(0, 0, self.upperView.frame.size.width, self.upperView.frame.size.height+expectedLabelSize.height);
}
[ self.upperView addSubview: descriptionLabel];
}
//black line
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(10, descriptionLabel.frame.origin.y + descriptionLabel.bounds.size.height+15, descriptionLabel.frame.size.width+50, 1)];
line.backgroundColor=[UIColor colorWithRed:164/256.0 green:165/256.0 blue:160/256.0 alpha:1.0];
line.tag=PopulateTag;
[self.upperView addSubview:line];
//this does not work pushes whole view down
//self.restOfView.frame=CGRectMake(10, line.frame.origin.y + line.bounds.size.height+1, self.upperView.frame.size.width, 600);
[restOfView reloadData];
在 IB 上:
这就是发生的事情:
Tableview需要在这里
我怎么解决这个问题?