繁体   English   中英

如何为 xamarin.forms iOS 中的条目单元格设置背景颜色和文本颜色?

[英]How to set a background color and text color to an entry cell in xamarin.forms iOS?

我是 Xamarin 表单的新手。 似乎没有属性可以在表视图中为 EntryCell 设置背景颜色或文本颜色。 当 iOS 的主题处于黑暗模式时,有没有办法自定义?

DarkMode 将文本颜色更改为与背景颜色相同的白色。 所以文字现在是不可见的

要设置background colortext color在一个EntryCell xamarin.forms iOS ,您可以使用自定义渲染器:

[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 { 

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM