简体   繁体   English

如何在Xamarin.Forms中为IOS平台创建更改UITableViewCellSelectionStyle

[英]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.

相关问题 如何更改 Xamarin.Forms ios 中的工具栏图标颜色 - how to change toolbar icon color in Xamarin.Forms ios iOS 15 更新后,iOS 平台中 Xamarin.forms 中的导航栏颜色变化问题 - Navigation bar colour change issue in Xamarin.forms in iOS platform after iOS 15 update 如何使用 Xamarin.Z6450242331912982ACA6663 下载公开可用的 Android X 和 iOS 上的文件? - How do I download a file on both Android X and iOS that is publicly available, using Xamarin.Forms? 如何更改 xamarin.forms ios 上的导航栏标题图标? - how to change navigation bar title icon on xamarin.forms ios? Xamarin.forms-如何在MapView上创建可拖动元素(标记)? - Xamarin.forms - How do I create draggable elements (Markers) on a MapView? 如何在iOS中设置Xamarin.Forms SearchBar的样式? - How can I style the Xamarin.Forms SearchBar in iOS? 如何在xamarin.forms中将UIImageView添加到UIAlertView? - How do I add UIImageView to UIAlertView in xamarin.forms? 如何在用户走过时跟踪GPS坐标,来自iama平台的xamarin.forms - How to track the GPS coordinates as user walks, from xamarin.forms for ios platform 如何在 Xamarin.Forms 中获取 iOS 和 Android 的辅助功能字体大小,以便我可以在 HTML WebView 中更改字体大小? - How to get the accessibility font size for iOS and Android in Xamarin.Forms so I can change font-size in a HTML WebView? 如何从Xamarin.Forms应用程序修改平台特定的属性? - How do you modify platform specific properties from a Xamarin.Forms application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM