UITableViewCell的detailTextLabel不使用所有可用空间

时间:2014-04-28 20:58:43

标签: ios uitableview detailtextlabel

As shown in the screenshot

如截图所示。只是想知道如何让detailTextLabel使用所有可用空间,比如红色矩形的区域。我试图设置detailTextLabel的框架以使宽度更大而不起作用。

提前谢谢。

2 个答案:

答案 0 :(得分:1)

我建议您继承UITableViewCell并将所有单元格自定义放入其中。它看起来与此代码类似:

CustomCell.h

@interface CustomCell : UITableViewCell

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier;

@end

CustomCell.m

#import "CustomCell.h"

@implementation CustomCell

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
    if (self)
    {
        // Customization not related to positions and sizes of subviews. For example:
        self.detailTextLabel.textColor = [UIColor lightGrayColor];
        self.detailTextLabel.text = @"Aaaaaa…";
    }

    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];

    // Customization related to positions and sizes of subviews. For example:
    self.detailTextLabel.frame = CGRectMake(10.0, 10.0, 240.0, 40.0);
}

@end

答案 1 :(得分:0)

让我们试试风格UITableViewCellStyleDefault

YourViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
    cell = [[YourViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
相关问题