objective-c - IOS11 UIContextualAction 放置图片颜色文字

标签 objective-c ios11

防止图片如何恢复真实颜色我现在放置的图片都是白色

- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0))
{

 UIContextualAction *deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:nil handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL))
    {
        NSLog(@"------------------>%@",sourceView);
        completionHandler (YES);
    }];

    deleteRowAction.image = [UIImage imageNamed:@"heart"];

    UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
         return config;


    return nil;

}

最佳答案

RSSReaderMaker 解决方案适用于 Swift 5 的小更新:

class ImageWithoutRender: UIImage {
    override func withRenderingMode(_ renderingMode: UIImage.RenderingMode) -> UIImage {
        return self
    }
}

并且在 trailingSwipeActionsConfigurationForRowAtleadingSwipeActionsConfigurationForRowAt

使用:

if let cgImageX =  UIImage(named: "x_blue_big")?.cgImage {
     action.image = ImageWithoutRender(cgImage: cgImageX, scale: UIScreen.main.nativeScale, orientation: .up)
}

关于objective-c - IOS11 UIContextualAction 放置图片颜色文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46398910/

相关文章:

ios - AVAudioPlayer 在 Debug模式下抛出断点

iphone - AppDelegate 中声明的变量是否可供所有其他类访问?

ios - 从 iOS 11 搜索 Controller 导航时不需要的 UITableView 重新加载动画

ios - 通过 URL Scheme 或其他方式打开 iOS 11 文件应用

iOS 11 UISearchBar 背景颜色

ios - 以编程方式更改推送通知内容

ios - 圆形的 UICollectionViewCell

ios - 在导航栏中使用弹出窗口时后退按钮仍然启用

ios - 一个函数中的 NSURLConnectionDelegate 回调

objective-c - UIScrollView setContentOffset :animated not working in iOS11