1

我无法让这个动态标签根据内容调整其高度。它记录了正确的信息,但标签始终是相同的高度。有任何想法吗?

        self.descriptionLabel.text = string;
        self.descriptionLabel.adjustsFontSizeToFitWidth = YES;


        self.descriptionLabel.numberOfLines=0;
        CGSize maximumLabelSize = CGSizeMake(296,9999);

        CGSize expectedLabelSize = [string sizeWithFont:[UIFont fontWithName:@"Helvetica" size:14] constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByWordWrapping];

        //adjust the label the the new height.
        CGRect newFrame = self.descriptionLabel.frame;
        newFrame.size.height = expectedLabelSize.height;
        NSLog(@"the height %f", newFrame.size.height);
        self.descriptionLabel.frame = newFrame;
4

1 回答 1

0
        CGSize constraintSize = CGSizeMake(requiredWidth, MAXFLOAT);

        CGSize labelSize = [requiredLableText sizeWithFont:requiredFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

        returned size will give u the dynamic height of the UILabel
于 2013-04-03T07:22:42.240 回答