更改 UITableView 中移动单元格的默认图标 [英] Change default icon for moving cells in UITableView
问题描述
我需要更改 UITableView 中移动单元格的默认图标.
I need to change default icon for moving cells in UITableView.
这个:
有可能吗?
推荐答案
这是一个非常棘手的解决方案,可能不会长期有效,但可能会给您一个起点.重新排序控件是一个UITableViewCellReorderControl
,但它是一个私有类,所以你不能直接访问它.但是,您可以查看子视图的层次结构并找到它的 imageView.
This is a really hacky solution, and may not work long term, but may give you a starting point. The re-order control is a UITableViewCellReorderControl
, but that's a private class, so you can't access it directly. However, you could just look through the hierarchy of subviews and find its imageView.
您可以通过子类化 UITableViewCell
并按如下方式覆盖其 setEditing:animated:
方法来实现:
You can do this by subclassing UITableViewCell
and overriding its setEditing:animated:
method as follows:
- (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"];
}
}
}
}
}
}
<小时>
或者在 Swift 中
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")
}
}
}
}
不过请注意...这可能不是一个长期的解决方案,因为 Apple 可以随时更改视图层次结构.
Be warned though... this may not be a long term solution, as Apple could change the view hierarchy at any time.
这篇关于更改 UITableView 中移动单元格的默认图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!