在UISwipeActionsConfiguration iOS 11 - Xamarin / Swift中更改文本和图像的颜色

7
我有一个UISwipeActionsConfiguration,用于iOS 11,代码如下:

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

有没有一种方法可以修改文本和图像的颜色? 因为我不知道怎么做,我尝试在用户滑动时在单元格上创建一个ImageView,但是该图像位于滑动视图的后面。感谢您的帮助,希望您能帮助我解决这个问题。


我认为你可以使用图片代替文本,因为使用工具(如Photoshop)很容易更改图片的颜色。 - ColeX
1个回答

2

实际上,使用API修改UISwipeActionsConfiguration来改变文本和图像的颜色是不可能的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接