我创建了CustomTableViewCell,它在我的xamarin应用程序中显示一些数据。在尾随滑动时,我使用4个选项按钮创建了SwipeActionConfiguration。我的目标是创建带有额外标签和图像视图的主刷自定义UIView。我的尾随滑动动作如下所示:
public UIContextualAction[] ContextualTrailingAction(int row)
{
var noteImage = UIImage.FromFile("pencil.png");
var phoneImage = UIImage.FromFile("phone.png");
var routeImage = UIImage.FromFile("map-marker.png");
var actionsImage = UIImage.FromFile("settings-option.png");
noteImage = iOSActions.GetColoredImage(noteImage, UIColor.Clear.FromHex(0xef9617));
phoneImage = iOSActions.GetColoredImage(phoneImage, UIColor.Clear.FromHex(0x54b854));
routeImage = iOSActions.GetColoredImage(routeImage, UIColor.Clear.FromHex(0x36b0d4));
actionsImage = iOSActions.GetColoredImage(actionsImage, UIColor.Clear.FromHex(0x2187ba));
List<UIContextualAction> actionsList = new List<UIContextualAction>();
List<UIImage> images = new List<UIImage>
{
noteImage, phoneImage, routeImage, actionsImage
};
List<int> colors = new List<int>
{
0xef9617, 0x54b854, 0x36b0d4, 0x2187ba
};
List<string> titles = new List<string>
{
"Notatka", "Telefon", "Wyznacz trasę", "Akcje"
};
titles.Reverse();
colors.Reverse();
images.Reverse();
foreach (var actionImage in images)
{
var action = UIContextualAction
.FromContextualActionStyle(UIContextualActionStyle.Normal,
"",
(OfferAction, view, success) =>
{
Console.WriteLine(OfferAction);
Console.WriteLine(view);
success(true);
});
action.Image = actionImage;
actionsList.Add(action);
}
for (var indx = 0; indx < actionsList.Count; indx++)
{
actionsList[indx].BackgroundColor = UIColor.Clear.FromHex(colors[indx]);
actionsList[indx].Title = titles[indx];
}
UIContextualAction[] actions = actionsList.ToArray();
return actions;
}
我使用如下自定义表将其添加到tableviewcell中:
public override UISwipeActionsConfiguration GetTrailingSwipeActionsConfiguration(UITableView tableView, Foundation.NSIndexPath indexPath)
{
var actions = ContextualTrailingAction(indexPath.Row);
var trailingSwipe = UISwipeActionsConfiguration.FromActions(actions);
trailingSwipe.PerformsFirstActionWithFullSwipe = false;
return trailingSwipe;
}
有人知道如何将UIView添加到行并向其添加滑动操作吗?