当我在textview上写长字时,我的代码不能正常工作,那么我的标签尺寸会增加,但是桌面高度不会随着标签的宽度和高度而增加。我的代码出了什么问题?
我在视图didload方法中写了这两行
Addresslbl = [[UILabel alloc]initWithFrame:CGRectMake(300, 10, 250, 30)];
Addresslbl.backgroundColor = [UIColor whiteColor];
并将代码写入-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row == 0 && indexPath.section == 3)
{
NSString *dispalynotes=@"";
dispalynotes=Peopledetailmodel.Address;
// dispalynotes=Addresslbl.text;
CGSize labelSize = CGSizeMake(200.0, 20.0);
if ([dispalynotes length] > 0)
labelSize = [dispalynotes sizeWithFont: [UIFont boldSystemFontOfSize: 17.0] constrainedToSize: CGSizeMake(labelSize.width, 1000) lineBreakMode: UILineBreakModeWordWrap];
return 25.0 + labelSize.height;
}
答案 0 :(得分:0)
您已在方法heightForRowAtIndexPath
中应用相同的逻辑 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if ([dispalynotes length] > 0)
labelSize = [dispalynotes sizeWithFont: [UIFont boldSystemFontOfSize: 17.0] constrainedToSize: CGSizeMake(labelSize.width, 1000) lineBreakMode: UILineBreakModeWordWrap];
return 25.0 + labelSize.height;
}