0

I have this code which run very well on XCode 4 / iOS 6 to add background image on window :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bgleft"]];
    return YES;

}

but today, when I try to put it into XCode 5 and try to build an app for iOS 7, it's not working anymore. is there something changed from XCode 4 to XCode 5?

thank you.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Saint Robson
  • 5,475
  • 18
  • 71
  • 118
  • @NguyenDuc : if you're using XCode 4.6, can you test your app in iOS7 device? because I already upgrade my device into iOS7 – Saint Robson Sep 20 '13 at 04:34
  • 1
    It seems like backgroundColor now only sets tintColor, not letting you change the style of the view. – Alejandro Iván Sep 20 '13 at 04:40
  • @AlejandroIván : I tried this `self.window.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"window"]];` but still can't change the window... – Saint Robson Sep 20 '13 at 04:41
  • 1
    No what I meant was that the setBackgroundColor method actually IS a setTintColor now. There should be no difference, but maybe I'm wrong. Have you tried using the `setBackgroundView` method? Would be someting like `[self.window.view setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgleft"]]]` or so... – Alejandro Iván Sep 20 '13 at 04:43
  • @AlejandroIván : no, I haven't tried `setBackgroundView` method, how's that? – Saint Robson Sep 20 '13 at 04:45
  • 1
    @Robert Hanson: You can use TestFlight to test a new app. You cannot use directly Xcode 4.6 build for iOS 7. But I'm sure you, the layout works fine on iOS7. – Duc Nguyen Sep 20 '13 at 04:58
  • 1
    Go ahead https://testflightapp.com/ – Duc Nguyen Sep 20 '13 at 04:58
  • @NguyenDuc : I'm thinking to take your advice... to downgrade my Xcode and also my iOS device. but I need your opinion... if I build my app specifically for iOS 7, what about users who have iOS 6 device? will they able to run my app? – Saint Robson Sep 20 '13 at 05:05
  • 1
    @Robert Hanson To run both version iOS 6 and iOS 7, You need change deployment target in general tab Xcode from greater 6.1 and otherwise set 7.0 only run for iOS 7 (use Xcode 5 to do that) – Duc Nguyen Sep 20 '13 at 05:14
  • 1
    @AlejandroIván 1) `backgroundColor` and `tintColor` are NOT the same. They do two completely different things. 2) `UIWindow` does NOT have a `view` property. And the only things that have a `backgroundView` property are collection views and cells and table views and cells. – rmaddy Sep 20 '13 at 05:14
  • @NguyenDuc : no, I mean, if I keep using Xcode 5 and I build my app specifically for iOS 7, which has coloured status bar, etc... will iOS6 users still able to download my app from AppStore? – Saint Robson Sep 20 '13 at 05:18
  • 1
    @AlejandroIván It depend deployment target in general tab Xcode that you set. If you want iOS6 device can run, you should set it 6.1 – Duc Nguyen Sep 20 '13 at 05:20
  • 1
    But, the layout in iOS 6 when build from xcode 5 has changed, you must change something to compatible with that – Duc Nguyen Sep 20 '13 at 05:21
  • @NguyenDuc : I'll take your advice... is to painful to use Xcode 5 and developing an app for iOS7 right now. Maybe next month everything will be different.. but since I have finish my app on schedule, I will consider to back to Xcode 4.6 and build for iOS 6. thanks for great advice, Nguyen! – Saint Robson Sep 20 '13 at 05:27

1 Answers1

0

Try adding a controller to your window:

UIViewController *controller = [[UIViewController alloc] init];
controller.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bgleft"]]; // (the error may be here, where's the extension for the image? ".png" for example
self.window.rootViewController = controller;
[self.window makeKeyAndVisible];
return YES;

And make sure the images extension is included within your code, and is also imported into the xcode project

Also if you're deploying on a retina display device, the image needs to include @2x after the name and before the extension, like so:

bgleft@2x.png
Rob
  • 631
  • 1
  • 7
  • 20