Sukma Saputra
Sukma Saputra

Reputation: 1599

How to Custom UINavigationController?

I have design goal like picture in this: enter image description here

The problem is, UIButton valign cannot in center position, UIButton always relative to UINavigationController like this: enter image description here

How to make UIButton valign in center of background image height not UINavigationController height?

Upvotes: 0

Views: 3371

Answers (5)

Varghese Abraham
Varghese Abraham

Reputation: 51

the prob you are facing because of the navigation bar height. Now there are two approaches. Either you can create a category for navigation bar and override the -(CGRect)sizethatFits method like given below: - (CGSize)sizeThatFits:(CGSize)size { CGSize newSize = CGSizeMake(320,100); return newSize; }

Or you can hide the navigation bar like : [self.navigationController setNavigationBarHidden:YES]; and put a header view and handle that.

Do what you would prefer to do..

Upvotes: 0

iPhone Programmatically
iPhone Programmatically

Reputation: 1227

 self.btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
[self.btnBack setImage:[UIImage imageNamed:@"back_active.png"] forState:UIControlStateNormal];
[self.btnBack addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
self.btnBack.frame = CGRectMake(5, 9, 50, 30);
[self.navigationController.navigationBar addSubview:self.btnBack];

check this link also.

Update:for back button

-(void)back
{

[self.btnBack removeFromSuperview];
[self.navigationController popViewControllerAnimated animated:NO];
}

Upvotes: 1

Toseef Khilji
Toseef Khilji

Reputation: 17409

There is trick,

You can Hide navigationController using [self.navigationController setNavigationBarHidden:YES];

and display custom view in top as you want.

Upvotes: 0

Agent Chocks.
Agent Chocks.

Reputation: 1312

This is a good quick solution

myButton.titleLabel.font = [UIFont fontWithName:@"FontName" size:20.0];   
myButton.contentEdgeInsets = UIEdgeInsetsMake(3.0, 0.0, 0.0, 0.0);

and hide your navigation bar by

[self.navigationController setNavigationBarHidden:YES];

then show your custom view

Upvotes: 0

Bhrigesh
Bhrigesh

Reputation: 871

First create custom button and then add subview in navigation controller :-

UIButton * headerButton = [UIButton buttonWithType:UIButtonTypeCustom];  
[headerButton addTarget:self action:@selector(headerButton1Action:) forControlEvents:UIControlEventTouchUpInside];
headerButton.frame = CGRectMake(95, 1, 30,38 );
[headerButton setImage:[UIImage imageNamed:@"header-icon"] forState:UIControlStateNormal];
[headerButton setImage:[UIImage imageNamed:@"header-icon-pressed"] forState:UIControlStateSelected];

[self.navigationController.navigationBar addSubview:headerButton];

I hope this will help you. Happy coding...

Upvotes: 0

Related Questions