UITableViewCell Accessory is too wide on iPad

后端 未结 3 733
悲&欢浪女
悲&欢浪女 2021-02-12 11:13

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 iPo

相关标签:
3条回答
  • 2021-02-12 12:00

    Use the width same as that of [UIApplication sharedApplication].keyWindow.frame.size.width rather than hardcoding the values.

    0 讨论(0)
  • 2021-02-12 12:02

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

    You can turn this feature off by setting

    tableView.cellLayoutMarginsFollowReadableWidth = false
    

    in viewDidLoad

    0 讨论(0)
  • 2021-02-12 12:17

    Try this code:

        protected void Draw()
            {
                Accessory = UITableViewCellAccessory.DisclosureIndicator;
    
                Layer.BorderColor = UIColor.Green.CGColor;
                Layer.BorderWidth = 1f;
    
                Frame = new CGRect(0, 0, [UIApplication sharedApplication].keywindow.frame.size.width, 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;
    
            }
    
    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, [UIApplication sharedApplication].keywindow.frame.size.width - 32, ContentView.Frame.Size.Height);
    
                foreach (var view in Subviews.OfType<UIButton>())
                {
                    view.Frame = new CGRect([UIApplication sharedApplication].keywindow.frame.size.width - 24, view.Frame.Y, 8, view.Frame.Height);
                }
            }
        }
    
    0 讨论(0)
提交回复
热议问题