Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 825
Brian David Berman Avatar asked Nov 15 '11 00:11

Brian David Berman


3 Answers

try setting the BackgroundColor of your View

myview.BackgroundColor = UIColor.FromPatternImage(UIImage.FromFile("myimage.png"));
like image 181
Jason Avatar answered Nov 15 '22 17:11

Jason


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

}
like image 41
Old Fox Avatar answered Nov 15 '22 19:11

Old Fox


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"));
}
like image 43
Sean Avatar answered Nov 15 '22 17:11

Sean