jansma jansma - 5 months ago 10
Swift Question

How to remove all navigationbar back button title

When I push a

UIViewController
, it has some title in back button at new
UIViewController
, if the title has a lot of text, It does not look good in iPhone 4s So I want to remove it.

If I add some code in
prepareForSegue
function, it is going to be a trouble.

Any better way to achieve this´╝č

Answer

If you want back arrow so following code put into AppDelegate file into didFinishLaunchingWithOptions method.

For Objective-C

 [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];

Another option give below.

In Objective C

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];

In Swift

self.navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style:.Plain, target:nil, action:nil)

So may be your problem has been solve.

Happy coding.

Comments