【问题标题】:Cell opacity Xamarin.Forms iOs细胞不透明度 Xamarin.Forms iOs
【发布时间】:2015-11-26 16:06:42
【问题描述】:

我已经为 iOS ListView 实现了一个自定义渲染器(带有 iOS ListView 的本机实现),现在,我需要为不同的单元格设置不透明度(如下图所示)单元格包含一些控件如:图像/文本标签/图像

我怎样才能做到这一点?

【问题讨论】:

    标签: c# ios xamarin.ios opacity xamarin.forms


    【解决方案1】:

    您不需要自定义渲染器来设置单元格的不透明度。只需设置列表的 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;
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-09
      • 2014-01-05
      • 2015-03-15
      • 1970-01-01
      • 2013-06-05
      • 1970-01-01
      • 2021-01-13
      相关资源
      最近更新 更多