【发布时间】:2014-11-19 18:11:02
【问题描述】:
我可以调整UITableview 的分隔线的高度吗?我在单元格处添加UIView作为分隔线,它很好,问题是当我滑动单元格删除它时,删除按钮是问题,它与分隔线重叠,或者我可以调整删除按钮的身高?
【问题讨论】:
标签: ios uitableview list-separator
我可以调整UITableview 的分隔线的高度吗?我在单元格处添加UIView作为分隔线,它很好,问题是当我滑动单元格删除它时,删除按钮是问题,它与分隔线重叠,或者我可以调整删除按钮的身高?
【问题讨论】:
标签: ios uitableview list-separator
Rashad 粘贴的代码很旧(找到 here),似乎不适用于 iOS 7 或 iOS 8。
这里是更新的代码:
-(void)layoutSubviews {
UIView *deleteButtonView = nil;
for (UIView *subview in self.subviews) {
// find the delete view in iOS 8
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]){
deleteButtonView = subview;
break;
}
// find the delete view in iOS 7
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellScrollView"]) {
for (UIView *secondSubview in [subview subviews]) {
if ([NSStringFromClass([secondSubview class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]) {
deleteButtonView = secondSubview;
break;
}
}
}
}
int heightOffset = 5;
CGRect buttonFrame = deleteButtonView.frame;
buttonFrame.origin.y = heightOffset;
buttonFrame.size.height = self.frame.size.height-2*heightOffset;
deleteButtonView.frame = buttonFrame;
}
【讨论】:
如果您无法调整删除按钮的大小,请调整底部UIView 的大小,使其与删除按钮重叠。
【讨论】:
我总是在单元格的 contentView 上像 subView 一样绘制分隔线。并在 tableView 中禁用 separatorStyle。并自定义删除按钮,如下所示:https://stackoverflow.com/a/22396248/887325
【讨论】:
在你的 TableViewCell layoutSubviews 方法中写这个:
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
UIView *deleteButtonView = (UIView *)[subview.subviews objectAtIndex:0];
CGRect newf = deleteButtonView.frame;
newf.origin.x = 250;
newf.origin.y = 47;
newf.size.width = 30;
newf.size.height = 50;
deleteButtonView.frame = newf;
}
希望这会有所帮助.. :)
【讨论】: