[英]How do I create change the UITableViewCellSelectionStyle for IOS platform in Xamarin.Forms
我需要将IOS列表视图的突出显示更改为红色。 到目前为止,我关注了论坛,并能够将cell.SelectionStyle设置为none。 当我在选项卡上选择时,高光不会出现。 但由于我的最终目标仍然是获得红色亮点? 有什么想法可以实现这一目标吗?
我已经阅读过论坛,他们说我应该在该线程中继承UITableViewCell类, 如何将UITableViewCellSelectionStyle属性设置为某些自定义颜色? 所以我尝试了
public void CustomUITableViewCell:UITableViewCell
{
public override virtual void SetHighlighted(bool highlighted, bool animated)
{
}
}
但是问题是当我尝试使用self时,我没有设置背景色的属性,所以现在该怎么办?
我只是将Objective-C转换为C#。
创建ViewCell
CustomRenderer,将SelectedBackgroundView
设置为Cell,整个代码如下。
[assembly: ExportRenderer(typeof(ViewCell), typeof(MyViewCellRenderer))]
namespace ProjectName.iOS
{
public class MyViewCellRenderer : ViewCellRenderer
{
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
{
var cell = base.GetCell(item, reusableCell, tv);
cell.SelectedBackgroundView = new UIView(cell.Bounds);
cell.SelectedBackgroundView.BackgroundColor = UIColor.Red;
return cell;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.