Multiple lines of a label in a custom UITableviewCell

后端 未结 5 1623
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-19 23:34

I have searched around for any tip for my problem. But I cannot find a solution for this.

I have made a subclass of UITableviewCell (FeedCell). With one image and t

相关标签:
5条回答
  • 2021-01-20 00:12

    Try putting the code that sets number of lines, linebreakmode, and font OUTSIDE of those curly braces

    0 讨论(0)
  • 2021-01-20 00:13

    I know this is an old post, but it came up when I was searching.

    I got an example like this by following http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout.

    I think for iOS8 the following is required:

    • Setting the lines to 0
    • Setting the word wrap
    • Setting the label size to be >= 20
    • Making sure there are enough constraints to determine the cell height (height of title and vertical spacing)
    0 讨论(0)
  • 2021-01-20 00:18

    try

    [tweetCell.tweetText  sizeToFit]
    
    0 讨论(0)
  • 2021-01-20 00:24

    Firstly, if you want to show 2 line of text (minimum 1 and maximum 2), the numberOfLines must be set to 2. Setting it to 0 means no limit.

    Secondly, setting just the number of lines is not enough. The label width HAS to be specified. Either use sizeToFit, or set a constant value.

    0 讨论(0)
  • 2021-01-20 00:25

    For mutiline use the following:

    tweetCell.tweetText.numberOfLines = 0;
    [tweetCell.tweetText sizeToFit];
    

    for testing purpose set the height of row as 46.0f in the following method:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    

    I could not get the height issue fixed but this did give me a UILabel with multiple lines

    0 讨论(0)
提交回复
热议问题