1

environment: creating an iPad application using Monotouch and the Monotouch.Dialog library.

I've been trying to set the background color on a DialogViewController to no avail. I have multiple views in my application being loaded an unloaded. For non of them I manage to set the background color.

What I have tried so far:

  • Set the background color on the main window of my application --> works fine.
  • Create a simple UIView, give it a size, set the background color and load it into the window --> works fine.

But as soon as I load a DialogViewController (with an associated view) the background color is always gray. The DialogViewController is used from the Monotouch.Dialog framework.

I'm pushing the DialogViewController onto a navigation controller to show a set of buttons laid out in a table view.

I must be missing out on something fundamental ! I have been looking through the Monotouch.Dialog code and tried a couple of other things, but nothing fixed my problem so far.

Any help highly appreciated.

boris

4

4 回答 4

14

您实际上需要将背景视图设置为空。这是表格视图后面的视图,例如 MonoTouch.Dialog 中的分组视图

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html

这是它的子类可能的样子:

 using System;
 using System.Drawing;
 using System.IO;
 using MonoTouch.Foundation;
 using MonoTouch.CoreGraphics;
 using MonoTouch.Dialog;
 using MonoTouch.UIKit;

 namespace MyNameSpace{

     public class MySpecialDialogViewController : DialogViewController {

       public MySpecialDialogViewController (UITableViewStyle style, RootElement root) 
              : base (style, root) 
         {
         }

        public override void LoadView ()
        {
            base.LoadView ();
            TableView.BackgroundView = null;
             TableView.BackgroundColor = UIColor.Black;
        }
     }

  }
于 2012-07-30T15:33:36.370 回答
8

MonoTouch.Dialog 文档中的“自定义 DialogViewController”部分对此进行了描述。

您需要继承 DialogViewController,如下所示:

public class ColoredViewController : DialogViewController {
    [...]

    public override LoadView ()
    {
        base.LoadView ();
        TableView.BackgroundColor = UIColor.Clear;
        ParentViewController.View.BackgroundColor = UIColor.Red;
    }
}
于 2011-09-06T15:28:00.277 回答
2

是的,埃里克的解决方案现在有效。如果您想使用图像而不是颜色,我在下面修改了他的内容。

        public override void LoadView () 
    {
        base.LoadView ();
        this.TableView.BackgroundView = null;
        //this.TableView.BackgroundColor = UIColor.Black;
        var background = UIImage.FromFile ("Images/down.png");
        this.TableView.BackgroundColor = UIColor.FromPatternImage(background);
    }
于 2012-11-28T20:39:11.313 回答
1

我发现使用其他解决方案时模式会重复,因此设置背景视图对我来说更可取,如下所示:

    public override void LoadView ()
    {
        base.LoadView ();
        UIImage tickImage = UIImage.FromBundle ("1.jpg");
        UIImageView backgroundImageView = new UIImageView (this.View.Bounds);
        backgroundImageView.Image = tickImage;
        backgroundImageView.ContentMode = UIViewContentMode.BottomLeft;  //your preference
        TableView.BackgroundView = backgroundImageView;
    }
于 2013-08-28T22:57:54.483 回答