Dla iOS potrzebny jest XF TableView TableViewRenderer z natywną kontrolą UITableView. Więcej tutaj:
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/renderers/
Poniżej jest rozwiązaniem. Kod w funkcji renderowania Draw należy zrobić w OnElementChanged ale niestety wydaje się Xamarin ma błąd https://bugzilla.xamarin.com/show_bug.cgi?id=58731 Innym problemem, który konwersji tekstu nie działa albo https://bugzilla.xamarin.com/show_bug.cgi?id=58732
One bardziej mały optymalizacji - Aby uniknąć robi konwersję tekstu w każdym renderer dodano narysowany tekst kontrolny czasu, zdekapitalizowany. Odpowiadając na inne pytanie, jak zmienić rozmiar tekstu dodałem hv.TextLabel.Font set (skomentowałem ale działa).
tak, pracując wokół tych 2 bugów:
XML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ButtonRendererDemo;assembly=ButtonRendererDemo"
x:Class="ButtonRendererDemo.CustomTablePage">
<ContentPage.Content>
<local:CustomTableView Intent="Settings">
<TableRoot>
<TableSection Title="First Case Sensitive Header">
<SwitchCell Text="New Voice Mail" />
</TableSection>
<TableSection Title="Second Case Sensitive Header">
<SwitchCell Text="New Mail" On="true" />
</TableSection>
</TableRoot>
</local:CustomTableView>
</ContentPage.Content>
</ContentPage>
kod Strona
namespace ButtonRendererDemo
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CustomTablePage : ContentPage
{
public CustomTablePage()
{
InitializeComponent();
}
}
public class CustomTableView : TableView
{
}
}
Renderer
[assembly: ExportRenderer(typeof(CustomTableView), typeof(CustomTableViewRenderer))]
namespace ButtonRendererDemo.iOS
{
public class CustomTableViewRenderer : TableViewRenderer
{
bool textDecapitalized = false;
public override void Draw(CGRect rect)
{
base.Draw(rect);
if (!textDecapitalized)
{
textDecapitalized = true;
var tableView = Control as UITableView;
var numSections = tableView.NumberOfSections();
for (nint s = 0; s < numSections; s++)
{
var hv = tableView.GetHeaderView(s);
if (hv != null) //always null in OnElementChanged. Bug reported
{
//unfortunately TextInfo doesn't work. Bug reported
//TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
// OR
//TextInfo textInfo = Thread.CurrentThread.CurrentCulture.TextInfo;
if (hv.TextLabel.Text.ToUpper().StartsWith("FIR"))
hv.TextLabel.Text = "First Case Sensitive Header";
else if (hv.TextLabel.Text.ToUpper().StartsWith("SEC"))
hv.TextLabel.Text = "Second Case Sensitive Header";
//hv.TextLabel.Font = UIFont.FromName(hv.TextLabel.Font.Name, 5f);
}
}
}
}
}
}
wynik końcowy z małej obudowie czcionki wrażliwej nagłówku
Hi Yuri, może pan pomóc z przykładu. Otworzę nagrodę za to jutro, więc może po zobaczeniu nagrody. – Alan2
Tak, to pytanie zasługuje na nagrodę :-) Pracując nad nim stworzyłem 2 błędy dla zespołu Xamarin :-) –