views:

317

answers:

3

I add a datetime label on the right of a table cell. When swip-to-delete shows the "Delete" button, the datetime label need to shift left a little bit. But how to get the "Delete" button's size?

I tried to find it in the cell.subviews but failed.

A: 

The delete button is 63x33.

Ray Wenderlich
but if it's in non-english the size will change.
al_lea
+1  A: 

You don't have to know the button's size. Instead, use the size of the cell's contentView property to calculate the sizes of the subviews. When swiping over a cell, UIKit will adapt the contentView's size and call layoutSubviews on the cell-object. In your subclass of UITableViewCell, overwrite the layoutSubviews method and set the appropriate sizes to the subviews.

Look at RecipeTableViewCell.m of Apple's iPhoneCoreDataRecipes sample code.

fjoachim
+1  A: 

The size adjusts to fit the text contained. See the following code:

- (NSString *)tableView:(UITableView *)tableView
titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"Dynamic width!";
}

vs

- (NSString *)tableView:(UITableView *)tableView
titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"⏎";
}
Max Kilgore