代码之家  ›  专栏  ›  技术社区  ›  Devarshi

如何根据行在表中的内容设置行高?

  •  6
  • Devarshi  · 技术社区  · 16 年前

    一般来说,表有固定的行高,但根据我的要求,我需要设置每一行的高度,根据它的内容。

    谢谢,

    米拉杰

    2 回复  |  直到 16 年前
        1
  •  6
  •   dj2    16 年前

    表视图委托协议具有 tableView:heightOfRow

        2
  •  1
  •   Andriy Joshua Nozzi    10 年前

    谢谢大家的建议和帮助。现在使用中的以下代码解决了此问题 tableView:heightOfRow:

    float colWidth = [[[tableView tableColumns] objectAtIndex:1]width];
    
    NSString *content = [[[tempArray objectAtIndex:row] objectForKey:@"tValue"] string];
    
    float textWidth = [content sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"Lucida Grande" size:15],NSFontAttributeName ,nil]].width;
    
    float newHeight = ceil(textWidth/colWidth);
    
    newHeight = (newHeight * 17) + 13;
    if(newHeight < 47){
        return 47;
    }   
    return newHeight;