I need to change the highlight of IOS list view to red color. As of now, I followed forums and was able to set the cell.SelectionStyle to 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? 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?
I just convert the Objective-C to C#.
Create CustomRenderer of ViewCell
, set SelectedBackgroundView
to Cell, the whole code as below.
[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;
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.