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.
Related
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.
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.
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];`
I have a really large image that I want to use as a background image of a view. However, I don't want to display the entire image at once; I want only a part of the image to be displayed, and then I want to animate it to display other parts of it, similar to the "infinite background" in games (only not infinite in my case ;)).
What is the best way to do this? Will I have to separate the image in several pieces and then somehow animate the transition between the pieces, or is there a better way?
How about having UIScrollView as a background view? You can then put UIImageView inside that scroll view and control scroll view's contentOffset as needed.
I found the solution. This piece of code does the magic:
self.backgroundImageView = [[UIImageView alloc] initWithFrame: self.view.bounds];
self.backgroundImageView.image = [UIImage imageNamed:#"background.png"];
self.backgroundImageView.contentMode = UIViewContentModeBottomLeft;
[self.view addSubview: self.backgroundImageView];
The key was setting the contentMode to UIViewContentModeBottomLeft.
I designed a very simple interface for an ipad device: UIView + a navigation bar.
Then after the view is load, it will download an image from a location and use the following method to display it:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
UIImage* testImg = [UIImage imageWithData:_networkData];
UIImageView* testView = [[UIImageView alloc] initWithImage:testImg];
[_view addSubview:testView];
[testView release];
}
The problem is now the new UIImage occupies the whole visible area of the Ipad.
I wonder how can I fix this issue? I suppose I have to find out the frame of the display area in the original view, and then assign it to the UIImageView instance?
initWithImage will automatically adjust the frame to match the size of the image you're passing in. To tell the UIImageView to take the same size as its parent view you could just add the following line before you add the subview:
testView.frame = _view.bounds
...we use bounds rather than frame because the superview may have an offset that we don't want the image view to have.