Brian David Berman
Brian David Berman

Reputation: 7684

Set background image in UIViewController (MonoTouch)

I have a screen called HomeScreen which implements UIViewController. I wish to use a background image for this screen. Is there an event that I can override to set this background image in the HomeScreen.cs file?

Upvotes: 10

Views: 16028

Answers (3)

Old Fox
Old Fox

Reputation: 8725

I voted up for the other answers, however today IPhone has different sizes and the correct way to load the image is using UIImage.FromBundle method:

Here is the assert catalog in the project:

enter image description here

To manage the images:

enter image description here

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

    // replace "name" with the desired name in the asset catalog
    this.View.BackgroundColor = UIColor.FromPatternImage(UIImage.FromBundle("name"));

}

Upvotes: 4

Sean
Sean

Reputation: 11

Try adding something like the following to your MyViewNameViewController.cs:

public override void ViewDidLoad()
{
    base.ViewDidLoad();
    this.View.BackgroundColor = UIColor.FromPatternImage(UIImage.FromFile("splash.png"));
}

Upvotes: 1

Jason
Jason

Reputation: 89117

try setting the BackgroundColor of your View

myview.BackgroundColor = UIColor.FromPatternImage(UIImage.FromFile("myimage.png"));

Upvotes: 13

Related Questions