我有UITableViewCell
,如下图所示。
单元格占据删除占用的高度。设置单元高度以便保持两个单元之间的间隔。
现在,当我滑动并删除按钮时出现(红色),它占据了上图中给出的单元格高度。我只想将其高度设置为仅白色部分的高度或者说出灰色按钮的高度。任何人都可以帮我了解如何设置在UITableViewCell
中滑动后显示的删除按钮的高度?
答案 0 :(得分:4)
解决这个问题的最佳方法是重写
-(void)layoutSubviews in YourCustomCell:UITableViewCell
然后
if ([NSStringFromClass([subview class])isEqualToString:@"UITableViewCellDeleteConfirmationControl"]){
UIView *deleteButtonView = (UIView *)[subview.subviews objectAtIndex:0];
CGRect buttonFrame = deleteButtonView.frame;
buttonFrame.origin.x = Xvalue;
buttonFrame.origin.y = Yvalue;
buttonFrame.size.width = Width;
buttonFrame.size.height = Height;
deleteButtonView.frame = buttonFrame;
}
答案 1 :(得分:4)
在自定义Cell类
中使用此代码 -(void) layoutSubviews
{
NSMutableArray *subviews = [self.subviews mutableCopy];
UIView *subV = subviews[0];
if ([NSStringFromClass([subV class])isEqualToString:@"UITableViewCellDeleteConfirmationView"]){
[subviews removeObjectAtIndex:0];
CGRect f = subV.frame;
f.size.height = 106; // Here you set height of Delete button
subV.frame = f;
}
}
答案 2 :(得分:3)
将此方法添加到customCell.m文件中。
-(void) layoutSubviews
{
NSMutableArray *subviews = [self.subviews mutableCopy];
UIView *subview = subviews[0];
if ([NSStringFromClass([subview class])isEqualToString:@"UITableViewCellDeleteConfirmationView"]){
UIView *deleteButtonView = (UIView *)[subview.subviews objectAtIndex:0];
CGRect buttonFrame = deleteButtonView.frame;
buttonFrame.origin.x = deleteButtonView.frame.origin.x;
buttonFrame.origin.y = deleteButtonView.frame.origin.y;
buttonFrame.size.width = deleteButtonView.frame.size.width;
buttonFrame.size.height = 46;
deleteButtonView.frame = buttonFrame;
subview.frame=CGRectMake(subview.frame.origin.x, subview.frame.origin.y, subview.frame.size.width, 46);
deleteButtonView.clipsToBounds=YES;
subview.clipsToBounds=YES;
}
}
答案 3 :(得分:3)
Swift 5,适用于 iOS12、iOS13 和 iOS14
func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
// for iOS13, iOS14
if let swipeContainerView = tableView.subviews.first(where: { String(describing: type(of: $0)) == "_UITableViewCellSwipeContainerView" }) {
if let swipeActionPullView = swipeContainerView.subviews.first, String(describing: type(of: swipeActionPullView)) == "UISwipeActionPullView" {
swipeActionPullView.frame.size.height -= 10
}
}
// for iOS12
tableView.subviews.forEach { subview in
if String(describing: type(of: subview)) == "UISwipeActionPullView" {
subview.frame.size.height -= 10
}
}
}
答案 4 :(得分:2)
对于IOS 13,位置已再次更改,而不是在表视图内更改,它再次在_UITableViewCellSwipeContainerView中。因此,您也应该对其进行迭代。请在下面查看
([NSStringFromClass([subview class])
isEqualToString:@"_UITableViewCellSwipeContainerView"]){
for (UIView *deleteButtonSubview in subview.subviews){
if ([NSStringFromClass([deleteButtonSubview class])
isEqualToString:@"UISwipeActionPullView"]) {
if ([NSStringFromClass([deleteButtonSubview.subviews[0] class]) isEqualToString:@"UISwipeActionStandardButton"]) {
//do what you want
}
}
}
}
答案 5 :(得分:1)
要了解它在IOS 11中的工作原理,请将此Swift 4代码段复制到UITableViewController中:
/var/lib/mysql/
此代码适用于IOS 11及更高版本
答案 6 :(得分:0)
在自定义单元格中写下以下代码,希望它对您有用 -
- (void)willTransitionToState:(UITableViewCellStateMask)state
{
[super willTransitionToState:state];
if(state == UITableViewCellStateShowingDeleteConfirmationMask)
{
[self performSelector:@selector(resetDeleteButtonSize) withObject:nil afterDelay:0];
}
}
- (void)resetDeleteButtonSize
{
NSMutableArray *subviews = [self.subviews mutableCopy];
while (subviews.count > 0)
{
UIView *subV = subviews[0];
[subviews removeObjectAtIndex:0];
if ([NSStringFromClass([subV class])isEqualToString:@"UITableViewCellDeleteConfirmationButton"])
{
CGRect f = subV.frame;
f.size.height = 74;
subV.frame = f;
break;
}
else
{
[subviews addObjectsFromArray:subV.subviews];
}
}
}
答案 7 :(得分:-1)
<强> SWIFT 强>
async asyncData ({ params }) {
const { data } = await axios.get ('/users/' + params.name)
return {
user: data.info
}
}