I have a subclassed UITableViewCell.
I need to dynamically change the frame of a UILabel.
Here\'s what I\'ve done:
- (UITableViewCell *)table
Did you consider overriding the - (void) layoutSubviews
method in your custom cell (i.e. MessageCell) and layout your stuff in there? I think this is the safest place to put layout changing code in, because in other places it may not have any effect. Don't forget to call [super layoutSubviews];
in your implementation of layoutSubviews
.
Consider going with this approach and let us know if it worked out for you!
But you need to consider performance implications with this approach, because layoutSubviews
will be called every time the table scrolls.
EDIT:
to accommodate for the right frame size for your label inside layoutSubviews
consider using - (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode
for the frame calculation.