Reputation: 12902
I've used the following code to make a cell indent from the left:
[cell setIndentationWidth:1];
[cell setIndentationLevel:15];
Unfortunately this offsets table view cell text labels when a cell contains a lot of text, so the problem here is that the ellipsis is the contents of the text label are further to the right and the ellipsis shows up further than usual when indenting from the left.
How can I make my UITableViewCell
's textLabel
have a right indent (or margin) as well?
Upvotes: 0
Views: 137
Reputation: 12902
I did the following (seems you can't just set the frame of the text label any other way).
Header (.h):
@interface UITableViewCellFixed : UITableViewCell
@property (nonatomic, assign) CGRect textLabelFrame;
@end
Implementation (.m):
@implementation UITableViewCellFixed : UITableViewCell
- (id)initWithLabelFrame:(CGRect)textLabelFrame {
self = [super init];
if (self)
self.textLabelFrame = textLabelFrame;
return self;
}
- (void) layoutSubviews {
[super layoutSubviews];
self.textLabel.frame = self.textLabelFrame;
}
@end
...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
UITableViewCellFixed *cell = [[UITableViewCellFixed alloc] initWithLabelFrame:CGRectMake(30, 0, tableView.frame.size.width - 60, 50)];
...
}
Upvotes: 1