?/** * incoming Uilabel control then makes an adaptive height * * @param lbl Control */-( CGFloat) Suitable: (uilabel*) lbl{ cgrect originalframe = lbl.frame; cgrect realframe =[lbl.text boundingrectwithsize:cgsizemake ( lbl.bounds.size.width, 1000) options:nsstringdrawinguseslinefragmentorigin attributes:@{ nsfontattributename:lbl.font} context:nil]; cgfloat allheight = 0; //determines whether the height of the control needs to be adjusted if (realframe.size.height > originalframe.size.height) { //Adjust the frame after adaptation realFrame.origin = originalFrame.origin; lbl.frame = realFrame; Calculate the change in height before and after adjustment cgfloat compareheight = realframe.size.height - originalframe.size.height; //gets all the child controls under the control loops Determines if its child control is located below the control's requires a y-axis offset adjustment Adjustment of the difference in height variation nsarray* arr = lbl.superview.subviews; for (UIView *subview in arr) { allHeight += subview.bounds.size.height; if (SUBVIEW.FRAME.ORIGIN.Y > ORIGINALFRAME.ORIGIN.Y) { cgrect subviewframe = subview.frame; subviewframe.origin.y += compareheight; subview.frame = subviewFrame; } } } return allheight;}
Automatic layout Common implementation method in UITableViewCell