2014-03-30 47 views
1

我有一個正規的UITableViewCell,當我向左滑動時,它顯示一個刪除按鈕。UITableView滑動刪除 - 對齊文本標籤

但是表視圖看起來是這樣的: enter image description here

我想什麼有在這裏是有textLabel s對齊的時候,刷卡時不外出的畫面。

這可以使用普通的UITableViewCells來完成嗎?我想過觀察cell.contentView的幀變化並相應地移動標籤(屏幕截圖上的紅色框爲cell.contentView s),但那些似乎始終始於{0,0}

我應該得到我自己的自定義類來獲得這種效果嗎?

回答

1

你可以做的是使用UITableViewCell的setEditing方法並調整框架或約束。如果標籤具有領先的限制條件,請參閱以下步驟 -

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    [super setEditing:editing animated:animated]; 
    NSInteger leadingSpace = 10; 
    NSInteger editingOffset = 82; 
    if (editing) { 
     self.labelLeadingContraint.constant = leadingSpace + editingOffset; 
    } else { 
     self.labelLeadingContraint.constant = leadingSpace; 
    } 
    [UIView animateWithDuration:0.5 animations:^{ 
     [self layoutIfNeeded]; 
    }]; 
}