这是一段代码,它可以显示带有一些自定义内容(颜色、图像)的UITableViewCell删除按钮,但是当我在iOS 11上更新之后,这个代码就不起作用了,而不是我的自定义按钮,我只有红色按钮。我又是如何理解苹果换键"UITableViewCellDeleteConfirmationButton“的。也许你知道怎么解决这个问题?
- (UIView*)recursivelyFindConfirmationButtonInView:(UIView*)view
{
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) {
// iOS 8+ code here
for(UIView *subview in view.subviews) {
if([NSStringFromClass([subview class]) rangeOfString:@"UITableViewCellActionButton"].location != NSNotFound)
return subview;
UIView *recursiveResult = [self recursivelyFindConfirmationButtonInView:subview];
if(recursiveResult)
return recursiveResult;
}
}
else{
// Pre iOS 8 code here
for(UIView *subview in view.subviews) {
if([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationButton"]) return subview;
UIView *recursiveResult = [self recursivelyFindConfirmationButtonInView:subview];
if(recursiveResult) return recursiveResult;
}
}
return nil;
}
-(void)overrideConfirmationButtonColor
{
dispatch_async(dispatch_get_main_queue(), ^{
UIView *confirmationButton = [self recursivelyFindConfirmationButtonInView:self];
if(confirmationButton)
{
self.buttonConfirm = [[UIButton alloc]initWithFrame:CGRectMake(13, 15, 90, 90)];
self.buttonConfirmAnimation = [[UIImageView alloc]initWithFrame:CGRectMake(12, 15, 40, 40)];
self.buttonConfirmAnimation.image = [UIImage imageNamed:@"heartWh"];
confirmationButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"patternPlist@2x"]];
[confirmationButton addSubview:self.buttonConfirmAnimation];
[confirmationButton bringSubviewToFront:self.buttonConfirm];
}
});
}
发布于 2018-05-23 16:15:00
我也遇到了同样的问题--因为iOS 11.x提议的解决方案不再有效。我注意到苹果不再使用UIButton作为删除按钮,而是使用一个名为UITableViewCellEditControl
的UIView,这个视图有两个子视图。
这两个子视图实际上是UIImageView类型,一个带有删除图标的彩色图像,另一个带有灰色版本(我猜是某种效果/阴影)。您仍然可以修改这些图像,例如设置它们的tintColors或完全更改图像。
不幸的是,现在还有两个额外的问题:
none
,也可以使用none
,即它可以是选择控件(空点/圆圈)。如果不使用实际的editingStyle和UITableView本身,这两种用法似乎是不可能区分的。UITableViewCellEditControl
中似乎存在一些潜在的逻辑,它将隐式地将图像重置为原始图像。https://stackoverflow.com/questions/46361103
复制相似问题