Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS11 UIContextualAction Place the image color text

To prevent the picture How to restore the real color I now place the image are white

- (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;

}
like image 398
刘明鑫 Avatar asked Sep 25 '17 06:09

刘明鑫


1 Answers

RSSReaderMaker solution work with small updates Swift 5:

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

And in trailingSwipeActionsConfigurationForRowAt or leadingSwipeActionsConfigurationForRowAt

Use:

if let cgImageX =  UIImage(named: "x_blue_big")?.cgImage {
     action.image = ImageWithoutRender(cgImage: cgImageX, scale: UIScreen.main.nativeScale, orientation: .up)
}
like image 80
UnRewa Avatar answered Oct 19 '22 23:10

UnRewa