[英]How do I create change the UITableViewCellSelectionStyle for IOS platform in Xamarin.Forms
I need to change the highlight of IOS list view to red color. 我需要将IOS列表视图的突出显示更改为红色。 As of now, I followed forums and was able to set the cell.SelectionStyle to none.
到目前为止,我关注了论坛,并能够将cell.SelectionStyle设置为none。 And the highlight does not appear when i select on a Tab.
当我在选项卡上选择时,高光不会出现。 But as my final goal is still to obtain a red highlight?
但由于我的最终目标仍然是获得红色亮点? Any ideas how I can achieve this?
有什么想法可以实现这一目标吗?
I have read forums and they said that I should subclass the UITableViewCell class in this thread How do I set UITableViewCellSelectionStyle property to some custom color? 我已经阅读过论坛,他们说我应该在该线程中继承UITableViewCell类, 如何将UITableViewCellSelectionStyle属性设置为某些自定义颜色? and so I tried
所以我尝试了
public void CustomUITableViewCell:UITableViewCell
{
public override virtual void SetHighlighted(bool highlighted, bool animated)
{
}
}
But the issue is when I tried, self does not have a background color property for me to set so what should I do now? 但是问题是当我尝试使用self时,我没有设置背景色的属性,所以现在该怎么办?
I just convert the Objective-C to C#. 我只是将Objective-C转换为C#。
Create CustomRenderer of ViewCell
, set SelectedBackgroundView
to Cell, the whole code as below. 创建
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.