2017-10-12 121 views
7

我有这个UISwipeActionsConfiguration适用于iOS 11这个代码看起来像更改颜色在UISwipeActionsConfiguration iOS的11文本和图像 - Xamarin /斯威夫特

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,但图像位于滑动视图的背面。感谢您的帮助,我希望您能帮助我。

+0

我认为你可以使用图像而不是文本,因为它很容易改变图像的颜色与工具(Photoshop等)。 –

回答

0

实际上修改UISwipeActionsConfiguration以更改文本的颜色,并且使用API​​的图像是不可能的。