Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resize UITableViewCell textLabel

I have a UITableViewCell that I would like to add a view to the right (in addition to the accessory view). I tried setting the size of textLabel to be a few pixels narrower but it just resizes it back.

Is there any way to resize textLabel?

like image 253
David Beck Avatar asked Jan 05 '10 19:01

David Beck


2 Answers

Actually it CAN be resized if you create an UITableViewCell subclass and override the layoutSubviews method:

- (void)layoutSubviews {
[super layoutSubviews];  //The default implementation of the layoutSubviews

CGRect textLabelFrame = self.textLabel.frame;
textLabelFrame.size.width = _textLabelMaxWidth;
self.textLabel.frame = textLabelFrame;
}

Hope it helps.

like image 113
Daniel Sanchez Avatar answered Sep 24 '22 02:09

Daniel Sanchez


The object referenced by the default textLabel property, in UITableViewCell instances of type UITableViewCellStyleDefault, cannot be resized, at least not in my experience. The best idea in these cases is to create your own subclass of UITableViewCell, in code or even with Interface Builder if you want, and give it the layout that you want.

like image 23
Adrian Kosmaczewski Avatar answered Sep 23 '22 02:09

Adrian Kosmaczewski