【发布时间】:2015-11-26 16:06:42
【问题描述】:
我已经为 iOS ListView 实现了一个自定义渲染器(带有 iOS ListView 的本机实现),现在,我需要为不同的单元格设置不透明度(如下图所示)单元格包含一些控件如:图像/文本标签/图像
我怎样才能做到这一点?
【问题讨论】:
标签: c# ios xamarin.ios opacity xamarin.forms
我已经为 iOS ListView 实现了一个自定义渲染器(带有 iOS ListView 的本机实现),现在,我需要为不同的单元格设置不透明度(如下图所示)单元格包含一些控件如:图像/文本标签/图像
我怎样才能做到这一点?
【问题讨论】:
标签: c# ios xamarin.ios opacity xamarin.forms
您不需要自定义渲染器来设置单元格的不透明度。只需设置列表的 itemTemplate(使用您的视图而不是 Grid。所有视图都有 Opacity 属性):
<ListView ItemsSource={Binding yourList}>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid Opacity="0.5">
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
即使所有这些事情,如果你仍然想用自定义渲染器来做,你的服装渲染器会是这样的:
[assembly: ExportRenderer(typeof(UIViewCell), typeof(UIViewCellRenderer))]
namespace YourProjectNamespace.iOS.Renderers
{
public class UIViewCellRenderer: ViewCellRenderer
{
public override UITableViewCell GetCell(Cell item,UITableViewCell reusable, UITableView tv)
{
var cell = base.GetCell(item, reusable, tv);
cell.BackgroundColor.ColorWithAlpha(0.5F);// set the opacity
return cell;
}
}
}
【讨论】: