UITableViewCell附件在iPad上太宽 [英] UITableViewCell Accessory is too wide on iPad

查看:91
本文介绍了UITableViewCell附件在iPad上太宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的UITableViewCell在iPad上出现问题。这个问题在iOS 7和现在之间出现了,但我不确定它何时开始。在iPod或iPhone上,我的手机看起来很好(纵向或横向),但在iPad上,显示配件非常宽。您可以在下图中看到一个示例。 tablecell有一个绿色边框,contentview有一个棕色边框。内容视图比应该小得多。没有公开附件的表格单元看起来很好。

I am having a problem with my UITableViewCell's appearance on the iPad. This problem arose sometime between iOS 7 and now, but I don't know for sure when it started. On an iPod or iPhone my cells look fine (portrait or landscape), but on the iPad, the disclosure accessory is very wide. You can see an example in the image below. The tablecell has a green border and the contentview has a brown border. The content view is much smaller than it should be. Table cells without the disclosure accessory look fine.

我正在使用Xamarin,我是在代码中完全创建此UI。这是代码(我已经省略了单元格ContentView内部的代码,因为它不相关:

I am using Xamarin, and I am creating this UI completely in code. Here is the code (I have omitted the code that lays out the inside of the cells ContentView since it isn't relevant:

protected void Draw()
    {
        Accessory = UITableViewCellAccessory.DisclosureIndicator;

        Layer.BorderColor = UIColor.Green.CGColor;
        Layer.BorderWidth = 1f;

        Frame = new CGRect(0, 0, 320, 42);
        ContentMode = UIViewContentMode.ScaleToFill;
        AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;

        ContentView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
        ContentView.MultipleTouchEnabled = true;
        ContentView.ContentMode = UIViewContentMode.Center;
        ContentView.ClipsToBounds = true;
        ContentView.Layer.BorderColor = UIColor.Brown.CGColor;
        ContentView.Layer.BorderWidth = 1f;

    }

我试过改变了通过覆盖单元格的LayoutSubviews方法来获取ContentView的大小。但是,ContentView现在和表格一样宽,但是披露附件没有改变,现在在ContentView下面。

I tried changing the size of the ContentView by overriding the cell's LayoutSubviews method. However, the ContentView was now as wide as the table, but the disclosure accessory didn't change and was now below the ContentView.

public override void LayoutSubviews()
    {
        base.LayoutSubviews();

        //ContentView.Frame = new CGRect(0, 0, Frame.Size.Width, ContentView.Frame.Size.Height);
    }

同样,这在iPhone或iPod上根本不是问题。我不明白我应该做些什么来让iPad正常工作。

Again, this isn't a problem at all on the iPhone or iPod. I don't understand what I should be doing different for the iPad to work properly.

谢谢。
Zach Green

Thanks. Zach Green

编辑 - 2015年10月21日11:00
目前,我做了一个非常hacky的变化正在为我解决这个问题,但我知道未来的iOS更新可能会打破这个,所以我更倾向于采用iOS批准的方式来实现这一目标。

Edit - 10/21/2015 11:00 For the moment, I have made a very hacky change that is fixing the issue for me, but I know that future iOS updates will probably break this, so I would prefer a more iOS approved way to do this.

public override void LayoutSubviews()
    {
        base.LayoutSubviews();
        //!! - Hack for ipad layout issue with disclosure indicator
        if (Accessory == UITableViewCellAccessory.DisclosureIndicator && UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
        {
            ContentView.Frame = new CGRect(0, 0, Frame.Size.Width - 32, ContentView.Frame.Size.Height);

            foreach (var view in Subviews.OfType<UIButton>())
            {
                view.Frame = new CGRect(Frame.Size.Width - 24, view.Frame.Y, 8, view.Frame.Height);
            }
        }
    }


推荐答案

这是由于Apples在iOS9中具有新的可读内容边距,旨在使内容在更广泛的视图中更具可读性(iPad Pro)。

This is due to Apples new readable content margins in iOS9 intended to make content more readable in wider views (iPad Pro).

您可以通过设置

tableView.cellLayoutMarginsFollowReadableWidth = false

在viewDidLoad中

in viewDidLoad

这篇关于UITableViewCell附件在iPad上太宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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