Joe
Joe

Reputation: 59

UITableViewCell's detailTextLabel not use all the available space

As shown in the screenshot

As shown in the screenshot. Just wondering how can I ask the detailTextLabel to make use all of the available space, say, the area of the red rect. I tried to set the frame of the detailTextLabel to make the width bigger which just doesn't work.

Thank you in advance.

Upvotes: 0

Views: 267

Answers (2)

Lebyrt
Lebyrt

Reputation: 1340

I'd recommend you to subclass a UITableViewCell and put all your cell customization in it. It could look similar to this code:

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

Upvotes: 1

nmh
nmh

Reputation: 2503

Let's try with style UITableViewCellStyleDefault

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

Upvotes: 0

Related Questions