Boris Rogge
Boris Rogge

Reputation: 35

How to set the background color on a DialogViewController (Monotouch.Dialog)

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:

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

Upvotes: 1

Views: 4048

Answers (4)

fractal
fractal

Reputation: 1679

I find the pattern gets duplicated when using the other solutions and so setting the backgroundview is more preferable for me like so:

    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;
    }

Upvotes: 1

darrellbooker
darrellbooker

Reputation: 188

Yes Eric's solution works now. I modified his below if you would like to use an image instead of a color.

        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);
    }

Upvotes: 2

Eric Welander
Eric Welander

Reputation: 560

You actually need to set the background view to null. This is the view that is behind a table view, such as the grouped one in MonoTouch.Dialog

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

Here is what a subclass for this might look like:

 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;
        }
     }

  }

Upvotes: 14

miguel.de.icaza
miguel.de.icaza

Reputation: 32694

This is described in the section "Customizing the DialogViewController" in the MonoTouch.Dialog documentation.

You need to subclass DialogViewController, like this:

public class ColoredViewController : DialogViewController {
    [...]

    public override LoadView ()
    {
        base.LoadView ();
        TableView.BackgroundColor = UIColor.Clear;
        ParentViewController.View.BackgroundColor = UIColor.Red;
    }
}

Upvotes: 8

Related Questions