Reputation: 1110
Let's say I have a UITableView that
I added an extra subview (let's say an UILabel) to the UITableView's cell's contentView. I want the UILabel's right border to be 10 pixels from the right cell border at all times.
I managed to do this for an initial drawing of the table view for any width by specifically setting the cells frame after dequeuing it which also updates the contentView's width (otherwise the cells seem to be 320 pixels wide all the time).
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID] autorelease];
CGRect oldFrame = cell.frame;
cell.frame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y, tableview.frame.size.width, oldFrame.size.height);
/* and other stuff */
}
Question: How can I keep the subviews of the cell's contentView aligned to the cell's right border when the table view's size changes at runtime?
Upvotes: 0
Views: 2147
Reputation: 69027
You could try setting your cell autoresizingMask
and its autoresizesSubviews
properties?
Possibly this would work:
cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth;
cell.contentView.autoresizesSubviews = YES;
you should also set the autoresizingMask
of your UILabel
, I think:
label.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth;
Upvotes: 2