Changing the default UITabBarController background color - iphone

So I have an iPhone application running that is controlled at the highest level by a UITabBarController. It is the default black Tab Bar at the bottom that you see in many iPhone apps. I am kind of new to iPhone SDK programming, and I know I have seen other apps that have their own background color for the Tab Bar at the bottom. I am not sure if they are using this tab bar as I am, as the main controller for their app, but the question applies to this:
How do I change the background color of the main UITabBarController in my application? I wanted to change it to a dark shade of green similar to the colors of the navigation bars and labels I have placed in my app. I find it weird how Apple makes it really easy to change the color of Navigation Bars (not controllers), and other things, but when it comes to controllers (in this case a Tab Bar Controller), I cannot find a single way to implement this cleanly and efficiently.

You can do something like this.
- (void)viewDidLoad {
[super viewDidLoad];
CGRect frame = CGRectMake(0.0, 0, self.view.bounds.size.width, 48);
UIView *v = [[UIView alloc] initWithFrame:frame];
[v setBackgroundColor:[[UIColor alloc] initWithRed:1.0
green:0.0
blue:0.0
alpha:0.1]];
[tabBar1 insertSubview:v atIndex:0];
[v release];
}

Related

How to get a fully transparent TabBar in UITabBarController [duplicate]

This question already has an answer here:
UITabBar fully transparent
(1 answer)
Closed 9 years ago.
I have spent the last few hours trying to get the TabBar in a UITabBarController fully transparent (clear background). I use a custom subclass of the UITabBarController and I managed to change the tintColor, the alpha, but the background color definitely remains the one defined in IB.
Thanks for your help, I'm getting crazy...
Here is one way to accomplish that.
CGRect frame = CGRectMake(0.0, 0.0, 320, 48);//Setting a Frame.
myTabView = [[UIView alloc] initWithFrame:frame];//Making Tab View
// not supported on iOS4
UITabBar *tabBarr = [self.tabBar tabBar];
if ([tabBarr respondsToSelector:#selector(setBackgroundImage:)])
{
// set it just for this instance
[tabBarr setBackgroundImage:[UIImage imageNamed:#"hot-1.png"]];
// set for all
// [[UITabBar appearance] setBackgroundImage: ...
}
else
{
// ios 4 code here
//[tabBarr setBackgroundColor:c];
}
//[myTabView setBackgroundColor:c];//Setting Color Of TaBar.
[myTabView setAlpha:0.8];//Setting Alpha of TabView.
[[self.tabBar tabBar] insertSubview:myTabView atIndex:0];//Inserting Tab As SubView.
And here is a link to a tutorial I found very useful in changing the tab bar's background. You can play around with the code and costomize it to your liking.
http://ios-blog.co.uk/tutorials/how-to-customize-the-tab-bar-using-ios-5-appearance-api/
Edit:
As far as setting the background color of tabbar to transparent or clear color, you have two ways. One is the image which I explained and you didn't like. The other one is to set the background of tabbar in its supper view. Something along the following line.
tabBar.superview.backgroundColor = [UIColor clearColor];
This way you reach behind the tabbar and change that black background to whatever you want.
Edit 1:
sorry for delay in adding the solution for ios 7. below is the method you need to change the background color of the tabbar in ios 7.
just add the following line of code inside your ViewDidLoad method and it will do the magic.
[self.tabBarController.tabBar setBackgroundColor:[UIColor greenColor]];
hope this helps.:)

Overlap navigation bar on ios 6 with other view

For an iphone project with an "unique" design (with which i am not happy at all) I need to draw a custom view which partially overlaps the navigation bar of a controller in a UINavigationController. Target is iphone/ios 6 with a fixed device orientation (portrait).
My currents solution is to disable the navigation bar programatically via self.navigationController.navigationBar.hidden = YES; in viewDidLoad of my controller and to draw a "fake" navigation bar and paint over this.
This leads to the problem that the status bar color remains black (since there is no real navigation bar visible).
Ios 6 status bar color is discussed here: Status bar color in iOS 6?
I already tried to use [self.view insertSubview:OVERLAPVIEW aboveSubView:self.navigationController.navigationBar] but it did not work and OVERLAPVIEW was drawn beneath the navigation bar.
Is there another way to overlap the navigation bar with another view (z-wise)?
Or is there a way to change the status bar color when no navigation bar is shown (unfortunately in addition to this the view with the overlap is the main view of the app and the first screen visible to the user)
Full disclosure: I am an ios noob and stack overflow lurker - this is my first question on stack overflow, please help me to clarify my question and improve my stack overflow skills if necessary.
Use
[self.navigationController.view addSubview:OVERLAPVIEW];
instead of
[self.view insertSubview:OVERLAPVIEW aboveSubView:self.navigationController.navigationBar];
You can adjust the frame of your view according to make navigation bar partially visible.
I solved this issue by hiding the Navigation bar with
self.navigationController.navigationBar.hidden = YES;
and by adding a navigation bar to my view. Everything added after this new navigation bar will to overlap it (you could use index [parentView.subviews objectAtIndex:0]; as well).
The color of the status bar changes as needed.
In the case of the splash screen i do exactly the same and overlap the navigation bar with the fullscreen splash image.
-(void)viewDidLoad{
[super viewDidLoad];
UINavigationBar * navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 49)];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:#"SPLASH"];
[navigationBar pushNavigationItem:item animated:NO];
[self.view addSubview:navigationBar];
CGRect frame = [[UIScreen mainScreen] bounds];
frame.origin.y -= 20;
UIImageView *splashImage = [[UIImageView alloc] initWithFrame:frame];
splashImage.image = [UIImage imageNamed:#"splash"];
[self.view addSubview:splashImage];
}
It seems that this answer solves my issue
Add UIView Above All Other Views, Including StatusBar
Note: at the moment i am not going down this road and I will accept this answer once I tried it (I postponed solving this problem at the moment and it might take a while)

iOS5 Toolbar background image

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"

How to change the highlighted color of a tabbaritem?

I am trying to change the highlighted color of the tabBarItem just like the Viber app does. I don't want to change the color of all the Bar, just the highlighted color.
I have read a lot posts here, but none of them explained how to do only this modification.
Does someone know how to do this? There is many apps that have customized colors!
Currently, with iOS4, this type of customization is not possible with a standard UITabBar. Most applications that have customized UITabBars actually create their own. Check out CocoaControls for some drop in third-party solutions you could use.
Have you tried:
UIView *bg = [[[UIView alloc] initWithFrame:CGRectMake(0,0,320,49)] autorelease];
[bg setBackgroundColor:[UIColor redColor]];
[self.tabBarController.tabBar insertSubview:bg atIndex:1];
That code initially creates a background view for the tabBar and sets it's colour to red.

How do i set the height of the UINavigationBar in an iphone app

Im using a typical situation with UINavigationController, id like to make the navigation bar a bit taller. setting its bounds and frame dont seem to make a difference, im using this code
//set up the navigation
UINavigationController *navigationController = [UINavigationController new];
[navigationController.navigationBar setBarStyle:UIBarStyleBlack];
[navigationController.navigationBar setTintColor:[UIColor purpleColor]];
[navigationController.navigationBar setBounds:CGRectMake(0.0, 0.0, 480.0, 100.0)];
[navigationController.navigationBar setFrame:CGRectMake(0.0, 0.0, 480.0, 100.0)];
but to no avail. any ideas?
I don't think you can change the height of a navigation bar. Except when you add a prompt message... But that's not what you want.
Frame is the visible area of a view. Bounds is the internal area. Usually this has an origin of (0, 0) and is as wide and high as the frame. However, when the content exceeds the visible area (like with a UIScrollView) the bounds can be larger (and the origin different). You rarely see bounds that are smaller than their respective frames.
EDIT: Looking at your code, what is [UINavigationController new] about? You should do [[UINavigationController alloc] init], shouldn't you?
Also, what you are doing is not really subclassing...
At the time of 2009, there is probably no way to change the height of UINavigationController. However, in iOS SDK 4.3, there is a way (hack).
To change the height of UINavigationController, change its frame size in viewWillAppear:animated: function. Then, the height will stay customized throughout whole app.
As far as I know the standard navigation bar height should not be changed.
"Specifically, it is alright to
modify the barStyle, tintColor, and translucent properties, but you
must never directly change UIView-level properties such as the frame,
bounds, alpha, or hidden properties directly."
If you like to customize the appearance of navigation bar you can use the appearance proxy [UINavigationBar appearance] in iOS 5