我需要更改 UITableView 中移动单元格的默认图标。
这个:
是否可以?
这是一个非常棘手的解决方案,可能无法长期工作,但可能会给您一个起点。重新排序控制是UITableViewCellReorderControl
,但这是一个私有类,因此您无法直接访问它。但是,您可以只查看子视图的层次结构并找到其 imageView。
您可以通过子类化来做到这一点UITableViewCell
并覆盖其setEditing:animated:
方法如下:
- (void) setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing: editing animated: YES];
if (editing) {
for (UIView * view in self.subviews) {
if ([NSStringFromClass([view class]) rangeOfString: @"Reorder"].location != NSNotFound) {
for (UIView * subview in view.subviews) {
if ([subview isKindOfClass: [UIImageView class]]) {
((UIImageView *)subview).image = [UIImage imageNamed: @"yourimage.png"];
}
}
}
}
}
}
或者用斯威夫特
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
if editing {
for view in subviews where view.description.contains("Reorder") {
for case let subview as UIImageView in view.subviews {
subview.image = UIImage(named: "yourimage.png")
}
}
}
}
但请注意...这可能不是一个长期的解决方案,因为苹果可以随时更改视图层次结构。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)