Xamarin.Forms:使用披露按钮时删除缩进 [英] Xamarin.Forms: Remove indentation when using a disclosure button

查看:109
本文介绍了Xamarin.Forms:使用披露按钮时删除缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在表格视图单元格上使用显示按钮.因此,我使用此自定义渲染器:

using HelloXamarinFormsWorld;
using HelloXamarinFormsWorld.iOS;
using UIKit;
using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using System.Drawing;
using ObjCRuntime;

/* Example of using a custom renderer to get the > disclosure indicator to appear */
[assembly: ExportRenderer (typeof (EmployeeCell), typeof (EmployeeCellRenderer))]

namespace HelloXamarinFormsWorld.iOS
{
    public class EmployeeCellRenderer : ViewCellRenderer
    {
        public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
        {
            var cell = base.GetCell (item, reusableCell, tv);

            cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;

//          // Remove seperator inset
//          if (cell.RespondsToSelector (new Selector ("setSeparatorInset:"))) {
//              cell.SeparatorInset = UIEdgeInsets.Zero;
//          }
//          // Prevent the cell from inheriting the Table View's margin settings
//          if (cell.RespondsToSelector (new Selector ("setPreservesSuperviewLayoutMargins:"))) {
//              cell.PreservesSuperviewLayoutMargins = false;
//          }
//          // Explictly set your cell's layout margins
//          if (cell.RespondsToSelector (new Selector ("setLayoutMargins:"))) {
//              cell.LayoutMargins = UIEdgeInsets.Zero;
//          }

            return cell;
        }
    }
}

如果设置了公开指示器,则会显示以下屏幕:

通常看起来像下面的样子

我尝试使用插图,但是必须在WillDisplay中,并且缩进也没有除去.在此线程 rmarinho 状态

您可以通过设置我认为的UIEdgeInsets进行修复,我在解决方案

我想这应该是Xamarin.Forms中的错误.

查看反编译的代码后,我发现默认的ViewCellRenderer试图通过计算单元格的内容视图来居中,这是不正确的,因为它没有考虑DisclosureIndicator的大小./p>

因此,解决方法是手动插入指示器( ExtendedViewCell所做的),并且不使用默认的公开指示器.

I want to use a disclosure button on my table view cell. Therefore I use this custom renderer:

using HelloXamarinFormsWorld;
using HelloXamarinFormsWorld.iOS;
using UIKit;
using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using System.Drawing;
using ObjCRuntime;

/* Example of using a custom renderer to get the > disclosure indicator to appear */
[assembly: ExportRenderer (typeof (EmployeeCell), typeof (EmployeeCellRenderer))]

namespace HelloXamarinFormsWorld.iOS
{
    public class EmployeeCellRenderer : ViewCellRenderer
    {
        public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
        {
            var cell = base.GetCell (item, reusableCell, tv);

            cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;

//          // Remove seperator inset
//          if (cell.RespondsToSelector (new Selector ("setSeparatorInset:"))) {
//              cell.SeparatorInset = UIEdgeInsets.Zero;
//          }
//          // Prevent the cell from inheriting the Table View's margin settings
//          if (cell.RespondsToSelector (new Selector ("setPreservesSuperviewLayoutMargins:"))) {
//              cell.PreservesSuperviewLayoutMargins = false;
//          }
//          // Explictly set your cell's layout margins
//          if (cell.RespondsToSelector (new Selector ("setLayoutMargins:"))) {
//              cell.LayoutMargins = UIEdgeInsets.Zero;
//          }

            return cell;
        }
    }
}

If I set the disclosure indicator I get the following screen:

Normally it does look like the following

I tried to play with the inset, but that has to be in WillDisplay and also the indentation is not removed. In this thread rmarinho states

you can fix by setting the UIEdgeInsets i think , i use the Padding property on ExtendedViewCell for this.

but I don't know where I should do this. Or how do I fix the indentation?

Edit:

Using cell.SeparatorInset = new UIEdgeInsets(0,0,0,0); didn't help.

解决方案

I guess it should be a bug in Xamarin.Forms.

After looking into the decompiled code, I have found that the default ViewCellRenderer tries to center itself by calculating the content view of the cell, which is not correct as it didn't consider the size of DisclosureIndicator.

So, the workaround is to insert an indicator manually (that's what ExtendedViewCell did) and do not use the default disclosure indicator.

这篇关于Xamarin.Forms:使用披露按钮时删除缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆