Change color for a text and image in a UISwipeActionsConfiguration iOS 11 - Xamarin / Swift
Asked Answered
B

1

7

I have this UISwipeActionsConfiguration for iOS 11 this code looks Like

enter image description here

public override UISwipeActionsConfiguration GetLeadingSwipeActionsConfiguration(UITableView tableView, NSIndexPath indexPath)
        {
            var definitionAction = ContextualDefinitionAction(indexPath.Row);
            var flagAction = ContextualFlagAction(indexPath.Row);
            var leadingSwipe = UISwipeActionsConfiguration.FromActions(new UIContextualAction[] { flagAction, definitionAction });

            leadingSwipe.PerformsFirstActionWithFullSwipe = false;
            return leadingSwipe;
        }


    public UIContextualAction ContextualDefinitionAction(int row)
    {
        string word = words[row];

        var action = UIContextualAction.FromContextualActionStyle(UIContextualActionStyle.Normal,
                                                            "Definition",
                                                            (ReadLaterAction, view, success) => {
                                                                var def = new UIReferenceLibraryViewController(word);

                                                                var alertController = UIAlertController.Create("No Dictionary Installed", "To install a Dictionary, Select Definition again, click `Manage` on the next screen and select a dictionary to download", UIAlertControllerStyle.Alert);
                                                                alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));

                                                                if (UIReferenceLibraryViewController.DictionaryHasDefinitionForTerm(word) || hasViewedAlert == true){
                                                                    PresentViewController(def, true, null);
                                                                    success(true);
                                                                }else{
                                                                    PresentViewController(alertController, true, null);
                                                                    hasViewedAlert = true;
                                                                    success(false);
                                                                }
                                                            });
        action.BackgroundColor = UIColor.Orange;
        return action;
    }

    public UIContextualAction ContextualFlagAction(int row)
    {
        var action = UIContextualAction.FromContextualActionStyle(UIContextualActionStyle.Normal,
                                                                  "Flag",
                                                                  (FlagAction, view, success) => {
                                                                        var alertController = UIAlertController.Create($"Report {words[row]}?", "", UIAlertControllerStyle.Alert);
                                                                        alertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); 
                                                                        alertController.AddAction(UIAlertAction.Create("Yes", UIAlertActionStyle.Destructive, null));
                                                                        PresentViewController(alertController, true, null);

                                                                      success(true);
                                                                  });

        action.Image = UIImage.FromFile("feedback.png");
        action.BackgroundColor = UIColor.Blue;

        return action;
    }

Exist a Way to modify the color of the text and the image? because I don't have a idea, I try creating a ImageView over the cell when the user swipe but the image is in the back of the view of the swipe. Thanks for the help and I hope you can help me with this.

Bioscopy answered 12/10, 2017 at 13:17 Comment(1)
I think you can use image instead of text, since it is easy to change the color of image with tool(photoshop etc.) .Somatoplasm
B
2

Actually modify UISwipeActionsConfiguration to change the color of the text and the image with the API is not possible.

Bioscopy answered 6/11, 2017 at 13:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.