Ios 如何将这些自定义单元格添加到TableView?
使用Xamarin.Forms,如何实现这样的布局 我说的是关于灰色背景的文字提示: 打开个人热点以共享 我可以添加到Ios 如何将这些自定义单元格添加到TableView?,ios,listview,xamarin,xamarin.forms,Ios,Listview,Xamarin,Xamarin.forms,使用Xamarin.Forms,如何实现这样的布局 我说的是关于灰色背景的文字提示: 打开个人热点以共享 我可以添加到列表视图或表格视图的所有内容都是标准的视图单元格,它们都使用分隔符和白色背景进行渲染 如果使用TableView或ListView无法实现此布局,我如何在标准StackLayout中呈现ViewCell(如示例图像中的Wi-Fi密码)呢?即使TableView没有现成的ViewCell,您当然可以推出自己的实现。显然有一个TextCell,但它不允许您指定字体大小和其他内容 你
列表视图
或表格视图
的所有内容都是标准的视图单元格
,它们都使用分隔符和白色背景进行渲染
如果使用
TableView
或ListView
无法实现此布局,我如何在标准StackLayout
中呈现ViewCell
(如示例图像中的Wi-Fi密码)呢?即使TableView没有现成的ViewCell
,您当然可以推出自己的实现。显然有一个TextCell,但它不允许您指定字体大小和其他内容
你可以这样做:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="DemoTableView.TablePage" Title="TableView">
<ContentPage.Content>
<TableView Intent="Settings">
<TableRoot>
<TableSection>
<SwitchCell Text="Personal Hotspot" />
<ViewCell> <!-- Simple text -->
<Label Text="Turn on personal hotspot..." FontSize="Small" ForegroundColor="Gray" />
</ViewCell>
<ViewCell> <!-- More complex cell -->
<StackLayout Orientation="Horizontal>
<Image Source="someicon" />
<StackLayout>
<Label Text="TO CONNECT USING WIFI" FontSize="Large"/>
<Label Text="Something more" FontSize="Small" />
</StackLayout>
</StackLayout>
</ViewCell>
</TableSection>
</TableRoot>
</TableView>
</ContentPage.Content>
</ContentPage>
即使TableView没有现成的
ViewCell
可以做到这一点,您也可以推出自己的实现。显然有一个TextCell,但它不允许您指定字体大小和其他内容
你可以这样做:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="DemoTableView.TablePage" Title="TableView">
<ContentPage.Content>
<TableView Intent="Settings">
<TableRoot>
<TableSection>
<SwitchCell Text="Personal Hotspot" />
<ViewCell> <!-- Simple text -->
<Label Text="Turn on personal hotspot..." FontSize="Small" ForegroundColor="Gray" />
</ViewCell>
<ViewCell> <!-- More complex cell -->
<StackLayout Orientation="Horizontal>
<Image Source="someicon" />
<StackLayout>
<Label Text="TO CONNECT USING WIFI" FontSize="Large"/>
<Label Text="Something more" FontSize="Small" />
</StackLayout>
</StackLayout>
</ViewCell>
</TableSection>
</TableRoot>
</TableView>
</ContentPage.Content>
</ContentPage>
谢谢,但是使用ViewCell有两个缺点:a)点击单元格时仍然会产生悬停效果,b)上面的SwitchCell的分隔符会稍微缩小,如果下面有更多选项,通常会缩小。有没有关于如何克服这些问题的想法?@Physikbuddha哦,对了,我没想到。我更新了我的答案。不过我不太确定b。谢谢,但是使用ViewCell有两个缺点:a)点击单元格时仍然会产生悬停效果,b)上面SwitchCell的分隔符会稍微缩小,如果下面有更多选项,通常会缩小。有没有关于如何克服这些问题的想法?@Physikbuddha哦,对了,我没想到。我更新了我的答案。不过我不太确定b。