Label auto-wrapping and custom label auto-wrapping in uitableview Cell

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.