Bacem
Bacem

Reputation: 207

Custom Navigation bar in iOS

Is it possible to add tow buttons under the navigation bar in iOS like shown in the image below:

If yes, please tell me how it can be done.

enter image description here

Upvotes: 2

Views: 728

Answers (2)

Shekhu
Shekhu

Reputation: 2020

Practically it's possible to do the same ;but i won't suggest you to do this,As this might break the app in upcoming release of iOS..

If you want to do this then check the post here on Stackoverflow

iPhone - How set uinavigationbar height?

it will helps you making the navigation bar taller. Simply create a custom UINavigationBar subclass, which overrides sizeThatFits: and returns a large size.

const CGFloat HeightToIncrease = 50.0f;

@implementation MyNavigationBar

- (CGSize)sizeThatFits:(CGSize)size {

    CGSize amendedSize = [super sizeThatFits:size];
    amendedSize.height += HeightToIncrease;

    return amendedSize;
}

@end

You view will looks like the ![following][1]

Now just override layoutSubviews in the navigation bar subclass and move the buttons and title up to make room for buttons

like following

- (void)layoutSubviews {
    [super layoutSubviews];     

    NSArray *classNamesToReposition = @[@"UINavigationItemView", @"UINavigationButton"];

    for (UIView *view in [self subviews]) {

        if ([classNamesToReposition containsObject:NSStringFromClass([view class])]) {

            CGRect frame = [view frame];
            frame.origin.y -= HeightToIncrease;

            [view setFrame:frame];
        }
    }
}

this will make the room for the buttons you want to place in the navigation .

Upvotes: 1

user4151918
user4151918

Reputation:

Look at the ExtendedNavBar example in Apple's Customizing UINavigationBar sample code.

Upvotes: 3

Related Questions