Forum Xamarin.iOS

how do add a background image to my view?

Le-royStainesLe-royStaines NZMember ✭✭

I can't figure out how to add a background image to my view. I can pick a color just fine but surely I can add an image? I've seen people who have done it using a pattern but I can't seem to translate it to Mono Touch.

Any help greatly appreciated.

Posts

  • GavinGrantGavinGrant GBUniversity ✭✭✭
  • VictorHGarciaVictorHGarcia USUniversity ✭✭

    I'm having the same issue like you @himanshu.8771‌ how did you fix it?

    Thanks

  • Le-royStaines.7824Le-royStaines.7824 NZMember ✭✭✭

    Are you doing it on the main UI thread? -make sure you are:

        public override void ViewWillAppear (bool animated) {
            this.InvokeOnMainThread (delegate {
                // UI stuff here
            });
        }
    

    I think the ViewWillAppear method is meant to be on the main thread anyway but I've had problems with this assumption before. Better to explicitly set any UI stuff to run on the main thread, to be sure.

  • How can i do for android

  • IshtiakAhmedIshtiakAhmed USMember
    edited December 2014

    Add the following code in your view controller:

    public override void ViewWillAppear (bool animated)
    {
    this.InvokeOnMainThread (delegate {
    this.View.BackgroundColor = UIColor.FromPatternImage(UIImage.FromFile("your-background.png"));
    });;

        base.ViewWillAppear (animated);
    

    }

  • jmccormickjmccormick USMember ✭✭
    edited January 2017

    @Manikandan.5390 said:
    How can i do for android

    This is the iOS form, but check out my question/answer here.

Sign In or Register to comment.