0

I'm trying to make a custom back button to pop back to parent in nav controller. I understand I should've made the back button in parent controller itself

self.navigationItem.backBarButtonItem= backBarButton

The button was just default button with custom text, but it worked. None of formatting or fonts showed up. So instead I made a custom leftBarButton in child VC:

UIButton *backBtn= [[UIButton alloc] init]; backBtn.backgroundColor = [UIColor clearColor]; backBtn.titleLabel.font = [UIFont fontWithName:@"CrimeFighter BB" size:20]; backBtn.titleLabel.textColor = [UIColor whiteColor]; backBtn.titleLabel.text = @"back"; [backBtn addTarget:self action:@selector(pop) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn]; self.navigationItem.leftBarButtonItem = backBarButton; 

Its working fine, but the button is not visible at all!

1 Answer 1

1

New attempt:

Doing an alloc & init on a UIButton isn't the right way to create a button in code.

The way to programatically create a button is:

UIButton * backBtn = [UIButton buttonWithType: UIButtonTypeRoundedRect]; 

Original attempt:

You need to give your custom back button a proper size. Try doing this before creating the "UIBarButtonItem".

backBtn.frame = CGRectMake(20.0f, 0.0f, 70.0f, 30.0f); 

The last number is the height and the second to last number is the button width.

Sign up to request clarification or add additional context in comments.

3 Comments

nopes. Its working fine as it was before, its just not visible
THat shows the rounded rect button with none of my formatting and UIButtonTypeCustom is still the same, working fine but nothing in place of left bar button
You may want to make certain that your custom font ("CrimeFighter BB") is actually on the iPhone or somewhere where the application can find & load it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.