The premise of line feed must be that there is enough height to change; otherwise, the excess part is not displayed.
Therefore, when setting the label line feed, consider the height of the cell, and the height of the Cell also needs to change. Let's not talk about the following code:
Cell. label. TEXT = [dict objectforkey: @ "info"]; cell. label. numberoflines = 0; // The cell can be displayed in multiple rows. label. linebreakmode = nslinebreakbywordwrapping; // split rows to set the label height [self changelabelheight: cell. label: cell. label. text]; // set the label height-(void) changelabelheight :( uilabel *) label: (nsstring *) string {nsdictionary * attribute =@{ nsfontattributename: [uifont systemfontofsize: 15]}; // calculate the actual size of the uilabel character display size = [String boundingrectwithsize: cgsizemake (145,100 0) // maximum width and height options: nsstringdrawinguseslinefragmentorigin attributes: attribute context: nil]. size; // reset the frame [label setframe: cgrectmake (label. frame. origin. x, label. frame. origin. y, size. width, size. height)]; nslog (@ "% lf", size. height );}
// Set the cell height // set the Row Height-(cgfloat) tableview :( uitableview *) tableview attributes :( nsindexpath *) indexpath {nsdictionary * attribute =@{ nsfontattributename: [uifont systemfontofsize: 15]}; nsdictionary * dict = [self. listdata objectatindex: indexpath. row + 1]; // obtain data. determine the length and height of cgsize = [[dict objectforkey: @ "info"] boundingrectwithsize: cgsizemake (156,100 0) based on the data) // maximum width and height options: nsstringdrawinguseslinefragmentorigin attributes: attribute context: Nil]. size; nslog (@ "Row heigth: % lf", size. height + 20); If (size. height + 20 <58) {return 58;} else {return size. height + 20 ;}}
Label auto-wrapping and custom label auto-wrapping in uitableview Cell