1
votes

I am new to Xamarin forms. Seems like there is no property to set the background color or text color for EntryCell in Table view. Is there a way to customize that when the theme of the iOS is in darkMode?

DarkMode changes the text color to white which is the same color for background. So the text is invisible now

1

1 Answers

1
votes

To set a background color and text color to an EntryCell in xamarin.forms iOS, you can use custom renderer:

[assembly: ExportRenderer(typeof(MyEntryCell), typeof(myEntryCelliOSCellRenderer))]
namespace App99.iOS
{
    public class myEntryCelliOSCellRenderer : EntryCellRenderer
    {

        public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
        {
            var nativeCell = (EntryCell)item;

            var cell = base.GetCell(nativeCell, reusableCell, tv);

            ((UITextField)cell.Subviews[0].Subviews[0]).TextColor = UIColor.Orange;
            ((UITextField)cell.Subviews[0].Subviews[0]).BackgroundColor = UIColor.Green;
            return cell;
        }
    }
}

And use it in Xamarin.forms project:

public partial class Page1 : ContentPage
{
    public Page1()
    {
        InitializeComponent();

        TableView tableView = new TableView
        {
            Intent = TableIntent.Form,
            Root = new TableRoot
            {
                new TableSection
                {
                    new MyEntryCell
                    {
                        Label = "EntryCell:",
                        Placeholder = "Type Text Here",                           
                    }
                }
            }
        };

        this.Content = new StackLayout
        {
            Children =
            {
                tableView
            }
        };
    }
}

public class MyEntryCell : EntryCell { 

}