5

My client can't read iPhone's default fonts, the size is too small. I have an application with a navigation bar and I need to make everything in it bigger, for example, the font's size.

IB doesn't seem to allow this... any help?

Many thanks!

Michael Mior
  • 28,107
  • 9
  • 89
  • 113
Hectoret
  • 3,553
  • 13
  • 49
  • 56

6 Answers6

13

Update: today (2012) there is a much bigger tendency towards custom UIs, so I would say the answer below is way too harsh. There is still no supported way of customizing height, though, but you can certainly derive from UINavigationBar and override some sizing methods. This probably will not get you rejected (although it is still a grey area, just something Apple will probably overlook today).

Once you get the size you want, you can use iOS 5 customization APIs to add the custom background image (see WWDC 2011 Session 114 - Customizing the Appearance of UIKit Controls).

Original answer from 2009:

This is generally impossible.

What's more, I believe making the navigation bar taller is a violation of Apple Human Interface Guidelines, and your application may be rejected from the App Store because of it. Please make sure your client understands this risk before proceeding.

(Pointing out rejection risks is usually a good way to convince clients against making nonsense decisions.)

Mazatec
  • 11,481
  • 23
  • 72
  • 108
Andrey Tarantsov
  • 8,965
  • 7
  • 54
  • 58
  • What about making the navigation bar fonts bigger? Is that possible and/or allowed? – Hectoret Jun 24 '09 at 17:38
  • At the very least you can use a custom title view, so I would count this as possible. Also I don't think you will be rejected because of a custom title view, so should be safe. I wouldn't recommend to try to play with the font size of the buttons. – Andrey Tarantsov Jul 10 '09 at 23:14
  • Disagree. First - It is possible by subclassing and overriding - (CGSize)sizeThatFits:(CGSize)size. Second - I'v seen many beautiful apps with customized navigation bars on the appstore. Sometimes it just make sense to have a fully customized nav bar for your app. – Avi Shukron Jan 04 '12 at 10:52
  • 4
    @AvrahamShukron Agreed with disagreement. My opinion was probably reasonable in 2009, but certainly not today. – Andrey Tarantsov Mar 20 '12 at 19:55
11

Many of the answers here are incorrect, or incomplete, so I wanted to add my answer here in the hope that it might enlighten some.

First off, there is nothing wrong with changing the height of the navigation bar. People commenting saying its not allowed, or goes against the guidelines are simply misunderstanding those guidelines.

The ability to adjust or alter the default navigation bar that's used inside a UINavigationController has been part of the SDK since iOS 5.

- (instancetype)initWithNavigationBarClass:(Class)navigationBarClass toolbarClass:(Class)toolbarClass NS_AVAILABLE_IOS(5_0);

The easiest way to change the height of the status bar is to use this method when initialising your navigation controller, passing in your custom UINavigationBar sub-class.

TestViewController *t = [[TestViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithNavigationBarClass:[MyNavigationBar class] toolbarClass:[UIToolbar class]];
[nav setViewControllers:@[t]];  
[self.window setRootViewController:nav];
[self.window makeKeyAndVisible];

Where an example of such a custom UINavigationBar class could look like:

@interface MyNavigationBar : UINavigationBar
@end

@implementation MyNavigationBar

- (CGSize)sizeThatFits:(CGSize)size
{
        CGSize s = [super sizeThatFits:size];
        s.height = 90; // Or some other height
        return s;
}

@end
Christian Neverdal
  • 5,655
  • 6
  • 38
  • 93
Skela
  • 884
  • 10
  • 18
7

If you decided to just change the font size in the navigation bar, you can do this (usually in your UIViewController's viewDidLoad method):

UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];

[titleLabel setBackgroundColor:[UIColor clearColor]];
// here's where you can customize the font size
[titleLabel setFont:[UIFont boldSystemFontOfSize:18.0]];
[titleLabel setTextColor:[UIColor whiteColor]];
[titleLabel setText:self.title];
[titleLabel sizeToFit];
[titleLabel setCenter:[self.navigationItem.titleView center]];

[self.navigationItem setTitleView:titleLabel];

[titleLabel release];
Marco Lazzeri
  • 1,808
  • 19
  • 15
5

By subclassing you can achieve that and still support iOS 3+:

Complete example:

#import <UIKit/UIKit.h>

@interface ASNavigationBar : UINavigationBar
@property (nonatomic , retain) UIImage *backgroundImage;
@end

And implementation:

#import "ASNavigationBar.h"

@implementation ASNavigationBar
@synthesize backgroundImage = _backgroundImage;

-(void) setBackgroundImage:(UIImage *)backgroundImage
{
    if (_backgroundImage != backgroundImage)
    {
        [_backgroundImage release];
        _backgroundImage = [backgroundImage retain];
        [self setNeedsDisplay];
    }
}

-(void) drawRect:(CGRect)rect
{
    // This is how the custom BG image is actually drawn
    [self.backgroundImage drawInRect:rect];
}

- (CGSize)sizeThatFits:(CGSize)size 
{
    // This is how you set the custom size of your UINavigationBar
    CGRect frame = [UIScreen mainScreen].applicationFrame;
    CGSize newSize = CGSizeMake(frame.size.width , self.backgroundImage.size.height);
    return newSize;
}
@end

Important notes:

  1. If the background image is with transparent areas, you have to set its barStyle property to "translucent" or the transparent areas will be black.
  2. If you have a NavigationBar taller than 44 points, you have to take into account that the position of the BarButtonItems might not be correct. They all will be anchored to the bottom of the bar. you can fix that by overriding layoutSubviews and change their origin.y value.
Avi Shukron
  • 6,088
  • 8
  • 50
  • 84
2

You should not change the height of the navigation bar. From Apple Programing Guide on View Controller:

Customizing the Navigation Bar Appearance

In a navigation interface, a navigation controller owns its UINavigationBar object and is responsible for managing it. It is not permissible to change the navigation bar object or modify its bounds, frame, or alpha values directly. However, there are a few properties that it is permissible to modify, including the following:

● barStyle property

● translucent property

● tintColor property

(taken from Apple: https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/NavigationControllers.html)

UPDATE -- IOS 7 --- still only the available properties can be changed but below is a great tutorial on how to achieve flexibility in the navigation bar http://www.appcoda.com/customize-navigation-status-bar-ios-7/

Gil Margolin
  • 1,959
  • 20
  • 21
0

To add to Skela's answer:

If you initiate your navigation controller in the Storyboard you can change the class of your UINavigationBar in the storyboard to your custom navbar.

enter image description here

enter image description here

and then implement the change height in the class

@interface MyNavigationBar : UINavigationBar
@end

@implementation SwitchAssessmentNavigationBar

- (CGSize)sizeThatFits:(CGSize)size
{
        CGSize s = [super sizeThatFits:size];
        s.height = 200; // Or some other height
        return s;
}

@end
HannahCarney
  • 3,441
  • 2
  • 26
  • 32