I am having trouble explaining this to myself but here is my best attempt.
I have a rootViewController that has a unique background imageView (placed in IB). When the user advances from that screen a navigationController is loaded in with a standard background color and can advance through the next screens. Is it possible to have just one image always stay as the background, i know i can use:
self.tableView.backgroundColor = [UIColor clearColor];
to allow the background to show through, but for some reason when i do this i see the first background image(the unique one), not the one that i have added to the Navigation controller.
This is the code that i use to add a bg to the nav controller:
UIImage *img = [UIImage imageNamed:#"v3_default_bg.png"];
UIImageView *bgView = [[UIImageView alloc] initWithFrame:self.view.frame];
bgView.image = img;
[appDelegate.navigationController.view sendSubviewToBack:bgView];
My question is this, is it possible to apply a non-unique background to the navigationController.
I also tried addSubview: instead of sendSubviewToBack: but that just blocks out my content. Could anyone lend me some thoughts? Thanks.
[appDelegate.navigationController.view sendSubviewToBack:bgView];
does not add the subview to the navigationController.view. You need to add it, then send it to the back:
[appDelegate.navigationController.view addSubview:bgView];
[appDelegate.navigationController.view sendSubviewToBack:bgView];
hide the navigation bar and then put Ur view there....
Related
Is there a way to have a background image remain constant across all views in a navigation controller? Currently I am loading the same background in each view's viewDidLoad method but this shows the background image move when navigating from view to view. I'd rather just the content of the view infront of the background "slide" on/off screen, but the background stay stationary. This is my current background image loading code:
UIImageView *background = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
background.image = [UIImage imageNamed:#"InfoBackground.png"];
[self.view addSubview:background];
[self.view sendSubviewToBack:background];
[background release];
Thanks!
Hm, perhaps if you look at the documentation (scroll down to Figure 2) you will get an idea of what you're dealing with. Because you are setting the background image for each of your view controllers that are being pushed into the UINavigationController, you will get that animation. What you need to do is set the background image into the nav controller itself.
I believe myNavController.view insertSubview:myImageView atIndex:0 should work. If your image needs to fill in behind the content view exactly, you could set the frame coordinates based on the coordinates and/or heights of the navbar and toolbar, which can be accessed through the navigation controller's properties. If not, just set the frame to the superview's bounds.
Let me know how it goes.
Edit: Oh, note that you would need to make sure each of your view controllers had transparent backgrounds.
i think the better idea is place background image on window and set all view's(all viewcontroller's view) background color to clear color [UIColor clearColor].
if you want background image static then there is only one way but i don't know that is possible or not, If we put image in window and make navigation controller transparent then it's stay static whatever you will do. because we are not changing window while push or pop.
I am just suggesting try this way i haven't tried like this.
I'm very new to iOS programming.
I'm trying to set the toolbar background to a custom image.
I'm also using storyboards.
How do I go about that?
Do I edit UIToolbar in the UI Kit framework? Do I need to change something in Storyboard?
Thanks,
You can use UIToolbar's built-in -setBackgroundImage:forToolbarPosition:barMetrics: method:
// portrait
[yourToolbar setBackgroundImage:[UIImage imageNamed:#"YourToolbarBkg-Portrait.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
// landscape
[yourToolbar setBackgroundImage:[UIImage imageNamed:#"YourToolbarBkg-Landscape.png"] forToolbarPosition:UIToolbarPositionAny barMetrics: UIBarMetricsLandscapePhone];
YourToolbarBkg-Portrait.png will be 320x44 bkg image for portrait mode
YourToolbarBkg-Landscape.png will be 480x32 bkg image for landscape mode.
UIToolbar inherits from UIView. This just worked for me:
[topBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:BAR_BKG_IMG]] autorelease] atIndex:0];
UPDATED
topBar ------ is the outlet of the UIToolBar u are using
use this code where u are creating ur UIToolBar the class which implements the UIToolbar..
plus tell me y r u using Toolbar whats ur main purpose for it
Instead of editing UIToolBar, why not create a UIView of the same size and skin that however you would like? That would be easier if you are new.
Or if you want to override UIToolbar:
#implementation UIToolbar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: #"image.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
#end
Had a right faff with background images for ToolBars and NavBars. I know setting the background image of a NavBar and ToolBar is generally a doddle. But, when you're presenting modal VC's, for some insane reason, where a NavBar is being added and you DO change the background image, it appears to double in size. Altering the height has strange results.
My issue was where I was using a NavController all over my App, but needed a modal view for one or two aspects of it. Simple enough. However, I needed either a NavBar or ToolBar type header with a Done button to pop the VC off the stack. Again, not an issue. But I needed the NavBar or ToolBar to look the same as everywhere else in my App.
I settled on a ToolBar, seeing as the VC was being presented modally. So, there my ToolBar sat, in typical Apple-blue. Nice, but not how the rest of my App looked, where a blackened image was being used for each NavBar. Using the iOS 5 appearance proxy, I altered the background image of the ToolBar. And this worked. But, unless I had the UIImage in exactly the proportions and size expected by the Tool Bar, I was in a pickle. The image simply did not look right at all. So, I decided to create a UIIMageView, where I could control the content mode, then insert a subview onto the toolBar.
Take a look at my code below.
UIImageView *toolbarImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:NAV_BAR_BACKGROUND]];
[toolbarImageView setFrame:[self.IBOToolBar bounds]];
[toolbarImageView setContentMode:UIViewContentModeScaleAspectFill];
[self.IBOToolBar insertSubview:toolbarImageView atIndex:1];
It's a bit of a fluff but I do hope this helps someone alter the image on their ToolBar.
NAV_BAR_BACKGROUND can be defined as follows:
#define NAV_BAR_BACKGROUND #"navBarBlackMattDarkSquare.png"
I know this is a very beginner question, but I'm obviously a beginner. I have already made a my TabBar but I want to set the background of one of the views as a (jpg) I created. I need to add the background in code (not IB) so that I can allow rotation and resizing when the iphone is rotated.
-thanks
You need to use a UIImageView, which is a subclass of UIView. You can create it as follows:
UIImageView *myImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"myImage.jpg"]];
[self.view addSubview:myImage];
[myImage release];
...so here I've created a UIImageView that uses a JPG called 'myImage' (it will automatically resize the view to fit the image), added it to my view controller, and then cleaned up my memory.
You can try this one to set an image as a background for a view programmatically:
view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"imageName.png"]]
Add an instance of UIImageView to your view, and set it's image to an instance of UIImage created using your file.
You can add the image view in IB or in code -- there's nothing about doing it in IB that would prevent you from resizing, rotating, etc.
I'd like to control visibility on a simple UI element. If it was a button, I'd just call setHiden on it, but UIImage has no such method.
What's the preferred way of showing or hiding an image? Just making it a UIButton and not hooking it up to any methods seems wasteful.. is that really the right way to do it?
Shouldn't your image be in an image view?
UIImageView imageView = [[UIImageView alloc] initWithImage:myImage];
Then you can hide the image view with:
imageView.hidden = YES;
hidden is a property of UIView, so you can use it with UIImageViews.
Adding an image to a UINavigationItem's titleView is pretty trivial, but when I push a new view on the stack it animates the UINavigationItem sliding off to the left, along with the titleView, and loads a new UINavigationItem.
I can think of a number of ways to go about making that image stay put, but they all seem pretty hacky. Is there a normal way of doing this that I can't find? Following is code for adding an image to my view controller's UINavigationItem:
UIImage *tImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"logo_topbar" ofType:#"png"]];
UIImageView *tImageView = [[UIImageView alloc] initWithImage:tImage];
self.navigationItem.titleView = tImageView;
[tImage release];
[tImageView release];
Thanks guys/gals
I imagine you could embed the entire view into a super-view, with the static image underneath your existing UI. You can then make the header in the UINavigationItems transparent, so the buttons will slide around over the image, but the image will stay put.
You can add the same titleView to all UIViewControllers that you would like it to appear on, I would guess however that this would let the ImageView be animated out to the left and a new identical one coming in from the right.
The only way I see is to add the UIImageView like this:
[self.navigationController.view addSubview:tImageView];
or try this
[self.navigationController.navigationBar addSubview:tImageView];