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

UILabel号码行

  •  1
  • Pablo  · 技术社区  · 14 年前

    我需要调整一下 numberOfLines 标签的位置 cellForRowAtIndexPath 然而,标签高度的实际计算是在 heightForRowAtIndexPath .

    如何计算 生产线数量 在里面 单元格行索引路径 ? 现在我用的是一个很大的数字。

    1 回复  |  直到 14 年前
        1
  •  2
  •   jessecurry    14 年前

    根据需要设置行数 将此属性的值设置为0。

    heightForRowAtIndexPath 方法来确定细胞的高度。

    常数:

    static const CGFloat kCellFontSize = 14.0;
    static const CGFloat kCellWidth = 300.0;
    static const CGFloat kCellHeightMax = 999.0;
    static const CGFloat kCellPadding = 10.0;
    

    方法:

    CGSize maxSize = CGSizeMake( kCellWidth, kCellHeightMax );
    
    CGSize labelSize = 
            [[self cellTextString] sizeWithFont: [self cellFont] 
                                    constrainedToSize: maxSize 
                                        lineBreakMode: UILineBreakModeTailTruncation];
    
    return (labelSize.height + (2 * kCellPadding));