How to set viewcontroller background image on iOS6 in 4 inch screen - ios

I need one clarification i have image size 640×1136 it is set view controller background full view this is set fine in iOS 7 because the status bar merge with view.
self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:#"iOS-7.png"]];
but in iOS 6 i can’t set the size of 640×1136 this image bottom size is hide. how to handle image on view controller background in iOS 6
How can i resolve the issue
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
imageView.contentMode = UIViewContentModeScaleToFill;
[imageView setImage:[UIImage imageNamed:#"iOS-7.png"]];
// self.view.backgroundColor = [UIColor colorWithPatternImage:imageView.image];
[self.view addSubview:imageView];
if i used this above code only worked fine. thanks for answer #Greg but i need to know why screen issues occurs on set self.view backgroundColor

So, iOS 7 switched the status bar to be translucent by default, and to allow content views to appear behind it. This is not the default for iOS 6. Hence, you're seeing your normal views start just below the status bar, and as you (weren't) scaling the view correctly, it was clipped.
You can get a similar effect for iOS 6 and below. Set the status bar to be translucent:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
and then, for each view controller you have, set:
myViewController.wantsFullScreenLayout = YES;
This should cause your views to extend below a translucent status bar, similar in style to iOS 7.

When you set up the image on imageView set scale mode:
imageView.contentMode = UIViewContentModeScaleAspectFit;
This should scale your image to fit full size of the view.
//Extended
When you use colorwithpattern... you can create UIImageView with size of your view add image to it with content mode = UIViewContentModeScaleAspectFit and after that call
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
imageView.contentMode = UIViewContentModeScaleAspectFit;
[imageView setImage:YOURIMAGE];
`self.view.backgroundColor = [UIColor colorWithPatternImage:imageView.image];`

Related

My image background covers all my outputs

Im a beginner in programing iOS, so I have 2 questions:
1- I have a UIViewcontroller which load a few uiview and user is able to move them via touch. Now I want to put an image background in this way:
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"board.png"]];
[self.view addSubview:backgroundView];
But the image covers over all uivews!!
2- As I said, I move my uiviews by touch and when they have collided in the end touch they both goes in a folder, and a folder is created. So I want to know how I can make that a special image shows on the created folder ??
if (view != toMove && CGRectContainsPoint(view.frame,toMove.center)) {
viewToBefolder = view;
}
You can add your background view first, and then the rest of the views you add will be on top, or just do this:
[self.view sendSubviewToBack:backgroundView];
If your image view is covering the the background, you should be setting the size and position of the image view, or setting the constraints so that it is added at the size and position that you want.
Set your imageview into the main window.
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"background.png"]];
[self.window addSubview:backgroundView];
[self.window sendSubviewToBack:backgroundView];
Then set all your view controller view clear color. so, By default it's always display background image view into the all view.

UIImageView - Stretch to fit issue

I have an app which requires dynamic background images (they are set server side) - the views used are both UIViewControllers and UITableViewControllers, so I have created classes which extend both controller type and add a background image to each view on load.
All works fine apart from the background image is refusing to stretch on an iPad on the UIViewController only - I am using Xcassets and have the standard and #2x retina images applied - all works fine on iPhone - and on both for UITableViewControllers but the UIViewController class doesn't appear to stretch the background on an iPad - it simply displays the image in the top left corner at the standard 320 width size.
This is my code - can anyone suggest where I am going wrong?
UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed: [self.prefs stringForKey:#"BGImageBlur"]]];
backgroundImage.contentMode = UIViewContentModeScaleToFill;
[self.view addSubview:backgroundImage];
[self.view sendSubviewToBack:backgroundImage];
You're creating a UIImageView and providing it the image to set within the view. This will create the UIImageView with the frame of the given Image. You must first specify the frame, then set the image. Try this:
UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame:self.view.bounds];
backgroundImage.image = [UIImage imageNamed:[self.prefs stringForKey:#"BGImageBlur"]]
This will create an ImageView that is the same size as its parent. If this is not what you want you'll probably have to specify some other layout constraints.

UIImageView over Navigation bar and main screen

I have an UImage that I need half on the navigation bar and half on the main screen. I have added a Navigation Controller on my project so now I have a nav bar on all screens. I need a square image to go half on the navigation controller and half on the main screen.
In XCODE I have successfully put an UImageView over the nav bar and the main screen but when i put an image on it i only appears in the part thats over the main screen and not over the navigation bar. I don't want to split the image so I can use Navigationbar.image control - is there another way ?
Instead of adding it to viewController, add it to window.
UIView *view =[[UIView alloc] initWithFrame:CGRectMake(40, 30,240,60)];
view.backgroundColor =[UIColor greenColor];
[[[UIApplication sharedApplication] delegate].window addSubview:view];
As you might have noticed the UINavigationBar appears on top of everything you have within your UIViewController's view.
One way of overcoming this is by adding your UIImageView to the keyWindow like so:
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
imageView.image = [UIImage imageNamed:#"myImage"];
[[UIApplication sharedApplication].keyWindow addSubview:imageView];

iOS launch image is different than background image size?

I have set up a launch image and this shows correctly when the app starts. In the initial view controller I do this in the viewDidLoad:
[self.imageBackground setImage:[UIImage imageNamed:#"Default.png"]];
Default.png is the same image as the launch image. Why does the image snaps (the image gets resized in the initial view controller) and how can I prevent this?
Thanks in advance
Try this.
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Default.png"]];
[self.view addSubview:backgroundView];
Add backgroundView.frame if you are facing any problem.
Its is based on your image view size in view controller. lets set image view size same as view size in view controller. It will reflect the same size.

adjusting view after hiding navigation bar

I have an app that has both navigationbar and toolbar on display with various buttons...
I have an imageview that will act as a help overlay (like you see in many apps these days) that is semi transparent with arrows pointing to the buttons on the bars plus actual view content.
First attempt displays the imageview in the view area but leaving the bars in place...not good!
So next attempt I have included the bars as part of the imageview and add this to take up the entire screen, so far so good. I then hide the bars but oh no.....the view moves up 44 pixels (as expected)
Problem is no matter what I do I cannot get the view to move down the 44 pixels?
So the imageview displays the bars giving the illusion the overlay (imageview) is on top, but the view in between is out of whack!
Does anyone know how to resolve this?
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(20, 0, 750, 1024)];
iv.userInteractionEnabled = YES;
iv.image = [UIImage imageNamed:#"myimage.png"];
UIWindow *window = self.view.window;
[window addSubview:iv];

Resources