iOS : background image black instead of requested image? - ios

I'm trying to set the background to an image.
code:
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"myPic"]]];
My original plan was to set the self.window to the background image and then have the other views be clear. (Using self.window in the app delegate) But after that turned our to give me a plain black screen (??) , I moved and adjusted the code to my RootViewController. I'm still getting a plain black screen. I tried using a few different images, yet I'm getting the same result on all of them. Any Ideas? Thanks!

The image name "myPic" should contain the file extension i.e. myPic.jpg

Related

React Native: change background color of initial loading view

When the React Native app is running at first, there is a white view like the screenshot bellow, how can i change that view's background color? I cannot find the activity in Xcode.
Because in some cases, i restart the app, and users sees a flash (the white screen above), so i need to change the background color.
Thanks in advance.
I just found it in AppDelegate.m
rootView.backgroundColor = [[UIColor alloc] initWithRed:0.0f green:0.64f blue:0.87f alpha:1];
Try changing the LaunchScreen file. It's the first thing that shows up when your app opens (If your bundling takes too long, you will see the white screen again. IMO the best practice is to use splash screen.
Using splash screen, you can dismiss the Splash View (probably an image) in your componentDidMount() function like below.
componentDidMount() {
// do anything while splash screen keeps, use await to wait for an async task.
SplashScreen.hide();
}
Also note that, in production release, there will be no bundling from the local server, so no need to worry that for now.

Can I Animate an image iOS8 LaunchScreen.xib

Question:
Are there ways to animate anything within the LaunchScreen.xib file of an Xcode 6 Project targeted to deploy for iOS 8.1+ ?
Context:
I'm looking to make simple animations to convey activity or serve as a distraction to the user while they wait...
Examples:
A Loading Bar
Activity Indicator
Animated GIF
Move a UIImage across the Screen
Rotate an Image
Nope.
The Launch Image is shown only during the time period between when the user chooses to launch your app and when your app has actually started running. During this period, your app can't take any actions such as performing an animation — it's not running yet. The Launch Image is just a static image that, when well designed, helps give the user the impression that your app is ready quickly.
(Some developers ignore the HIG and use the launch image to provide a splash screen, sometimes with an animated presentation. But in those cases, the launch screen is still a static image, and the animation happens once the app begins running — it's just that the first frame of animation drawn by the running app matches the appearance of the static launch image.)
This behavior didn't change with the LaunchScreen.xib feature in iOS 8 — it still appears only before your app is actually running, so it's still a static image. What the LaunchScreen.xib feature gets you is the ability to adaptively produce a launch image for many different device sizes and styles without having to separately design, render, and ship in your app bundle different images for each size/orientation/etc.
If your app isn't actually ready to use by the time it gains control, think about whether the "loading" tasks you're doing at that time really need to be done immediately, or if you can let the user start doing some things right away and do more setup work on a background thread or defer it until it's actually needed.
I don’t use splash screens often but when I do, I want them to open like a book.
In all truth, I’m not a big fan of splash screens and even Apple recommends using a default.png that shows the controls (with no text) of the application:
Display a launch image that closely resembles the first screen of the application. This practice decreases the perceived launch time of your application.
Avoid displaying an About window or a splash screen. In general, try to avoid providing any type of startup experience that prevents people from using your application immediately.
from HIG Guidelines
However, some people love them and one app in particular has a nice implementation splash screen — Path 2.0. When you open Path, you’re greeted with their logo on a red version of the Apple linen texture that animates open like a book (or journal as that’s what Path considers themselves to be).
You can get the source for this project here: https://github.com/jaysonlane/OpenBook
Before we begin, let me preface this with a disclaimer: I am very new to animations in Cocoa so bear with me. If you spot unnecessary or inefficient code, please leave a comment and I’ll tidy it up.
If you haven’t seen the animation, hop on the app store and pick up a copy to see what we’re trying to accomplish. I’ve created a default png that we can use cleverly titled Math (like a Math book that opens, right?) You can download that here (retina) and here.
To get started, let me explain “the trickery” behind what we’ll be doing: we’re going to use the normal default splash system in place to display our default.png. In the App Delegate, once the application has finished launching, we’re going to create a UIImageView on top of our view of that same default.png. We’ll then animate that UIImageView, to rotate open to reveal our view.
So let’s go:
Create a new project, I created one using the single view template but this will work with whatever. Go ahead and set your default.png and default#2x.png to the images supplied. You can do this by clicking the project in the navigation pane on the left, click the Target and scroll down to launch images:
Open your AppDelegate.m and add the following code to your application didFinishLaunching or application didFinishLaunchingWithOptions function:
//1. add the image to the front of the view...
UIImageView *splashImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[splashImage setImage: [UIImage imageNamed:#"Default"]];
[self.window addSubview:splashImage];
[self.window bringSubviewToFront:splashImage];
//2. set an anchor point on the image view so it opens from the left
splashImage.layer.anchorPoint = CGPointMake(0, 0.5);
//reset the image view frame
splashImage.frame = CGRectMake(0, 0, 320, 480);
//3. animate the open
[UIView animateWithDuration:1.0
delay:0.6
options:(UIViewAnimationCurveEaseOut)
animations:^{
splashImage.layer.transform = CATransform3DRotate(CATransform3DIdentity, -M_PI_2, 0, 1, 0);
} completion:^(BOOL finished){
//remove that imageview from the view
[splashImage removeFromSuperview];
}];
Three things are happening here…
1) We create a new UIImageView and add it to the top of the view
2) We set an anchor point on the left side of the image to make it open from the left and then reset the frame to the full size of the view
3) We animate the UIImageView and remove it from the view on completion
That’s it, it’s that simple.
Source: http://jaysonlane.net/tech-blog/2012/03/path-2-0-style-animated-splash-screen-default-png/
You can create the LaunchScreen.xib and then create a perfect replica that you can put code on and have a class like LaunchScreenAnimator that you can call form your delegate and that has a delegate to tell you when the animation is over
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
LaunchScreenAnimator *la=[LaunchScreenAnimator createWithDelegate:self];
self.window.rootViewController=la;
[self.window makeKeyAndVisible];
[la startAnimation];
return YES;
}
-(void) splashAnimationFinished:(LaunchScreenAnimator*)view
{
[self startWithDashboardWindow]; // replace the current rootViewController with whatever you want
}

UINavigationBar appearance background image duplicated and blurred in iOS 7.1

I have an interesting issue with an existing project and iOS7.1, I think. I've had code working and performing normally; since updating XCode and my iOS on my devices I have a problem, a transparent background image used in the Navigation Bar for that project is now rendered twice, once at the correct size and again blown up and blurry. The code only adds the image via the [UINavigationBar appearance] api in the app delegate. To check that this wasn't a specific bug with my code I create a default xcode project using the master detail default, set it to be iPhone only, added some newly created images and set them using the same calls in the app delegate. This project had the same issue and is on github here:
UINavigationBarBug github source
This is the relevant chunk of code imo:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"TLS.png"]
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBarTintColor:RGB(233, 155, 20)];
[[UINavigationBar appearance] setTintColor:RGB(245, 245, 245)];
return YES;
}
A screenshot of the problem:
Looking at the transition documentation what i am doing here should be fine, the navigation bars at 44 points high should be scaled horizontally and not vertically. I'm also pretty sure this problem never occurred prior to the update (it would have been spotted by internal QA prior to uploading the code to apple for review).
Two things fix it:
1) Using non transparent images, if it still has the problem it is loading the 'correct' image second and due to the lack of transparency overriding the incorrectly rendered one.
2) Using a navigation bar that is 66 points high instead (available in the project with a top transparent section as TLS-ios7), changing the code in the app delegate to use that fixes the problem.
Can anyone enlighten me as to what is going on here? Is this a bug, is it my fault, is there some section of documentation that informs me why this is so?
Thanks!
** Update: I recently found an iPad lying around still running iOS 7.0, this problem does not occur. **
I had a similar issue on my app. I solved it by setting the "translucent" of my UINavigationBar to NO.
[self.navigationController.navigationBar setTranslucent:NO];
You can disable image stretching by defining left and top caps.
Here's a Swift 3 solution:
let navbarImage = image.stretchableImage(withLeftCapWidth: 1, topCapHeight: 1)
UINavigationBar.appearance().setBackgroundImage(navbarImage, for: .default)
Example before:
and after the fix:
I just received this following my bug report... tl;dr It's me providing an image with an incorrect height:
Workaround for iOS 7.1 is to specify a resizable image with a non-zero inset. Internally UINavigationBar will tile your image if it isn't quite the right size and that is basically what was happening here – since the image wasn't tall enough (the navigation bar is top attached, so the image needed to be 64pt tall not 44pt) it would get tiled. If you set it to stretch and configure the cap insets such that it only stretches pixels that are uniform you should be able to avoid this issue.
I had a similar looking issue and it turns out I didn't have the correct image assets in the assets catalog. I only had retina assets but when I imported, they went into the 1x box in the asset catalog - moving them to the 2x box fixed my nav bar for me.
I had a similar problem, I had a logo with transparent background. Height was fine. Added in coloured background and the problem stopped.

UIImage looks different when used in iOS

I am having problems with a png image, that gets wrong colors on iOS compared to the actual image.
It does not matter how I am using the image, it always gets the wrong colors. I have tried on UIButton and UIImageView and it gives the same result.
It is a very standard use of a UIImage:
UIImage* greenButtonImg = [UIImage imageNamed:#"btn_green"];
UIImageView* testView = [[UIImageView alloc] initWithImage:greenButtonImg];
[self.view addSubview:testView];
The second image is how it looks on iOS and the first button is how it looks on my Mac (Finder and Photoshop):
As you can see the second button has a different green color.
This is happening all over the app where am using this picture. It happens in the Simulator and on a iPhone 5.
What can cause this issue? Can this be caused by settings in Photoshop, where the image was created?
As Jeff wrote in a comment it was a problem with the RGB Profiles.
I managed to fix the problem by converting the color profile in Photoshop:
Edit -> Convert to Profile... -> Set profile to "Apple RGB"
In iOS 7.0, the image is colored with the toolbar’s tintColor.
In iOS 7.0, all subclasses of UIView derive their behavior for tintColor from the base class.
By default, an image (UIImage) is created with UIImageRenderingModeAutomatic.
If you have UIImageRenderingModeAutomatic set on your image, it will be treated as template or original based on its context.
Certain UIKit elements—including navigation bars, tab bars, toolbars, segmented controls—automatically treat their foreground images as templates, although their background images are treated as original.
Other elements—such as image views and web views—treat their images as originals. If you want your image to always be treated as a template regardless of context, set UIImageRenderingModeAlwaysTemplate.
If you want your image to always be treated as original, set UIImageRenderingModeAlwaysOriginal.
Refer Template Images for more info.

Background Images On iOS

I'm created a Master Detail app on Xcode 4.x for iPad. I've tried adding a custom background image to the detail part of it which works fine the problem is the background image is appearing pixalated. The image is of size 2048 x 1546 (for the Retina screen on my iPad) and if I view it as a photo on the iPad it doesn't appear pixalated so why does it when it's being used as a background?
The code I'm using to set it is,
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"leather.png"]];
self.view.backgroundColor = background;
The only thing I could think of is because a Master Detail app has the scroll bar at the side but how would I fix that? Or what is the real cause? It appears pixalated or any orientation.
Add an image with the filename "leather#2x.png", otherwise UIImage won't recognize that it's supposed to be a high-resolution image. Alternatively, you may want to use a regular UIImageView instead of a pattern color.

Resources