我有一个普通的 UITableViewCell
,当我向左滑动它时,它会显示一个删除按钮。
但是 TableView 看起来像这样:
我想要的是让 textLabel
始终对齐,滑动时不会离开屏幕。
这可以使用常规的 UITableViewCells 来完成吗?我考虑过观察 cell.contentView
的框架变化并相应地移动标签(屏幕截图上的红框是 cell.contentView
),但那些似乎有一直在 {0,0}
的原点。
我应该得到我自己的自定义类来获得这种效果吗?
最佳答案
您可以做的是使用 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];
}];
}
关于ios - UITableView 滑动删除 - 对齐文本标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22751155/