Gabriel Goncalves
Gabriel Goncalves

Reputation: 5160

Navigation bar item not showing complete

I can see just this (text should be "item" and it is showing "I...m")

enter image description here

When I try to add a navigation bar item using the storyboard. Anybody know why? This is how I'm adding that button:

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

Upvotes: 0

Views: 202

Answers (1)

MSU_Bulldog
MSU_Bulldog

Reputation: 3519

Put a UIButton as the customView of the UIBarButton to set a custom width of the UIBarButton.

// create the nav bar back button
UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 24)];
[backButton setTitle:@"Item" forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = buttonItem;

Upvotes: 1

Related Questions