[英]Cell opacity Xamarin.Forms iOs
I have implemented a custom renderer for iOS ListView (with native implementation of iOS ListView) and now, I need to set the opacity for different cells (like in the image below) The cells contains some controls like : image/textlabel/image 我已经为iOS ListView实现了自定义渲染器 (使用iOS ListView的本地实现),现在,我需要为不同的单元格设置不透明度(如下图所示)。这些单元格包含一些控件,例如:image / textlabel / image
How can I achieve that? 我该如何实现?
You don't need custom renderer for setting the opacity of a cell. 您不需要自定义渲染器即可设置单元格的不透明度。 All to do is set the itemTemplate of list (Use your view instead of Grid
. All View has Opacity
property): 所有要做的就是设置列表的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>
Even all those things if you still want to do it with custom renderers, your costum renderer will be like: 即使所有这些事情,如果您仍然想使用自定义渲染器,costum渲染器也将像:
[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;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.