我需要创建一个带有图像和文本的动作按钮。下面的图片提供了一个例子。
:https://i.stack.imgur.com/KEuHn.png
我已经创建了一个方法
public UIContextualAction ContextualFlagAction(int row)
{
var action = UIContextualAction.FromContextualActionStyle(UIContextualActionStyle.Normal, "Flag", Handler);
(contextualAction, view, handler) =>
{
Console.WriteLine("Hello World!");
handler(false);
});
action.Image = UIImage.FromFile(ResourceIdentifiers.DocumentIcon);
return action;
}但这不是我需要做的。
如何将此操作自定义为上面的图像。
发布于 2018-10-30 03:36:28
可能您的问题是图像结果,您的代码已经设置了action.image,如果您有一个包含图片和标签的图像,图片是向上的,标签是向下的,会有您想要的。
public UIContextualAction ContextualFlagAction(int row)
{
var action = UIContextualAction.FromContextualActionStyle(UIContextualActionStyle.Normal, "Flag", Handler);
(contextualAction, view, handler) =>
{
Console.WriteLine("Hello World!");
handler(false);
});
action.Image = UIImage.FromFile(ResourceIdentifiers.DocumentIcon);
//this is your setted image
return action;
}更多信息:
您可以在TableViewCell中自定义Xamarin.ios。
在视图单元格中编写以下方法,在视图单元格中重写DidTransitionToState方法,可以用按钮替换操作
private UITableView tableViewThis;
public TableViewCellClass(UITableView tableView)
{
this.tableViewThis = tableView;
}
public override void DidTransitionToState(UITableViewCellState mask)
{
base.DidTransitionToState(mask);
if ((mask & UITableViewCellState.ShowingDeleteConfirmationMask) == UITableViewCellState.ShowingDeleteConfirmationMask)
{
foreach (UIView subview in tableViewThis.Subviews)
{
if (subview.Class.Equals("UIContextualAction"))
//Delete the delete button of the system
tableViewThis.WillRemoveSubview(subview);
subview.BackgroundColor = UIColor.Clear;
UIButton editBtn = new UIButton(UIButtonType.Custom);
editBtn.Frame = new CGRect(10, 4, 50, 65);
editBtn.SetBackgroundImage(UIImage.FromFile("1.png"), UIControlState.Normal);
editBtn.AdjustsImageWhenHighlighted = false;
editBtn.TouchUpInside += (sender, e) =>
{
//do something you need
};
subview.AddSubview(editBtn);
}
}
}UIButton可以同时设置标题和图像。UIButton有两个属性:
titleEdgeInsets(top,左,下,右)
和imageEdgeInsets(top,左,下,右)。
通过设置这两个,您可以实现所需的样式。
https://stackoverflow.com/questions/53048355
复制相似问题