UITableViewCell Accessory is too wide on iPad

后端 未结 3 732
悲&欢浪女
悲&欢浪女 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: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())
                {
                    view.Frame = new CGRect([UIApplication sharedApplication].keywindow.frame.size.width - 24, view.Frame.Y, 8, view.Frame.Height);
                }
            }
        }
    

提交回复
热议问题