Skip to content

Instantly share code, notes, and snippets.

@jaygarcia
Created March 20, 2016 13:15
Show Gist options
  • Save jaygarcia/c70e7285a013ec44ff57 to your computer and use it in GitHub Desktop.
Save jaygarcia/c70e7285a013ec44ff57 to your computer and use it in GitHub Desktop.
Set iOS lowest most view background to an image for ReactNative.
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"GORUCK"
initialProperties:nil
launchOptions:launchOptions];
// JG: Configure the scaled image for the background
CGRect bounds =[UIScreen mainScreen].bounds;
UIGraphicsBeginImageContext(bounds.size);
[[UIImage imageNamed:@"goruck_wallpaper"] drawInRect:bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.window = [[UIWindow alloc] initWithFrame:bounds];
// JG: Set the background image
self.window.backgroundColor = [UIColor colorWithPatternImage:image];
// JG: Set the rootView background color to opaque
rootView.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
// http://moduscreate.com
@pietro909
Copy link

Thank you for sharing, I'm using this snippet thou I get a stretched image. Is there a way to set the width?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment