【发布时间】:2020-04-14 05:58:29
【问题描述】:
我是 Xamarin 表单的新手。似乎没有属性可以在表格视图中为 EntryCell 设置背景颜色或文本颜色。当 iOS 的主题为 darkMode 时,有没有办法自定义?
DarkMode 将文本颜色更改为与背景颜色相同的白色。所以文本现在是不可见的
【问题讨论】:
标签: xamarin xamarin.forms xamarin.ios custom-renderer
我是 Xamarin 表单的新手。似乎没有属性可以在表格视图中为 EntryCell 设置背景颜色或文本颜色。当 iOS 的主题为 darkMode 时,有没有办法自定义?
DarkMode 将文本颜色更改为与背景颜色相同的白色。所以文本现在是不可见的
【问题讨论】:
标签: xamarin xamarin.forms xamarin.ios custom-renderer
要将background color 和text color 设置为xamarin.forms iOS 中的EntryCell,您可以使用自定义渲染器:
[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;
}
}
}
并在 Xamarin.forms 项目中使用它:
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 {
}
【讨论】: