简体   繁体   中英

Set navigation bar back button text IOS

Hi I am developing Iphone application in which I want to set some text for my back button. I tried in following way :

    self.navigationController.navigationBar.topItem.title = @"NOTIFICATION";

It is working fine if I gave small text but if I gave long text then it is not showing my text. Instead of that it is showing default "Back" text. How to do this? Any one know about it? Need some help. Thank you.

It is the default behaviour brother.

If you want to display long text (which you should not - because if you display long back button text then there'll be no space available to display TITLE of current view controller.)

Although you can achieve it using your own back button (Write below code in the viewcontroller2 ).

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"asdas" forState:UIControlStateNormal];
[button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 100, 44);
[button addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = customBarItem;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM