Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8217343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:25:41+00:00 2026-06-07T12:25:41+00:00

I have an iPhone app made up of a single UIWebView that displays a

  • 0

I have an iPhone app made up of a single UIWebView that displays a website. I have set a background image to the UIWebView after it finishes loading within my ViewController.m file, as shown here:

- (void)webViewDidFinishLoad:(UIWebView *)webView {
     // Set UIWebView Background Image
     self->webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ui-background-portrait.png"]];
}

This is fine when the device is in Portrait orientation, but I would like to change the background image if the user switches the device orientation to landscape, and back to portrait if they switch again, etc.

I wrote the code below, but I’m not sure where to put it (as it needs to change the background image whenever they switch orientations; not just one time):

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    // Set UIWebView Background Image
    if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
    {
        // code for Portrait orientation  
        self->webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ui-background-portrait.png"]];
    }
    if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
    {
        // code for landscape orientation  
        self->webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ui-background-landscape.png"]];
    }
}

How can I accomplish this? And if you could give me code and indicate where to put it, that would be such a great help 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:25:42+00:00Added an answer on June 7, 2026 at 12:25 pm

    Override one of these methods in your view controller and put your code there.

    – willRotateToInterfaceOrientation:duration:

    – willAnimateRotationToInterfaceOrientation:duration:

    – didRotateFromInterfaceOrientation:

    Put this code in your ViewController.m

    - (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfaceOrientation
    {
        // Set UIWebView Background Image
        if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
        {
            // code for Portrait orientation  
            self->webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ui-background-portrait.png"]];
        }
        if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
        {
            // code for landscape orientation  
            self->webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ui-background-landscape.png"]];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made an app that implements the iPhone's camera. When the user finishes
I have an iPhone app that displays a modal view controller. The modal view
I have an iPhone app that is using CoreData. I recently made some minor
I have made an iPhone App which has a loginwithFacebook button , the login
I have made an app which uses DropBox SDK for iPhone to connect to
I have an iPhone app that I've built for the app store. Before I
I have an iPhone app that I am writing and it has 2 targets
I have an iPhone app that allows users to record videos and I'd like
I have an iphone app i want that befor moving to next screen it
I have an iPhone app running in the simulator that won't quit. I also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.