0
votes

I have written a subclass of UITableViewcell which consists of various UILabels I have defined style of UIlabel in

  • (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier

and frame rect of labels in

  • (void)layoutSubviews

Now after defining static rect for UILabels I want to modify the rect of UILabels, and write a function to do so in which I am modifying the frame labels, but calling this function doesn't modify the frame of UILabels.
If anyone has idea how to achieve dynamic frame of labels please share it.

1
I'm a bit confused by the wording of your question. You want to change the rect but not the frame? I'm not sure that makes sense. - Alan Moore
If you only need to set the x-coordinates of the labels, then you can have a look at my github project's floating list - tipycalFlow

1 Answers

0
votes

The way that I typically achieve this is by implementing a custom tableviewcell and implement my own drawRect method in a subview where I specify the size of the label, something like this:

@implementation CompositeSubviewBasedRestaurantCellContentView

- (id)initWithFrame:(CGRect)frame cell:(RestaurantCell *)cell
{
    if (self = [super initWithFrame:frame]) {
        _cell = cell;

        self.opaque = YES;
        self.backgroundColor = _cell.backgroundColor;
    }

    return self;
}
- (void)drawRect:(CGRect)rect
{
    _highlighted ? [[UIColor whiteColor] set] : [[UIColor blackColor] set];
    [_cell.name drawAtPoint:CGPointMake(11.0, 22.0) withFont:[UIFont boldSystemFontOfSize:17.0]];
}

I think the Apple examples are pretty good, for instance the Table View Suite:

https://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007318