2

I have a leftBarButtonItem (using a custom view) that's acting as a replacement for a back button (as custom views can't be used on backBarButtonItem). I've also got a rightBarButtonItem (also using a custom view) and a custom titleView.

Everything works fine and dandy when the leftBarButtonItem is smaller than a certain width. The rightBarButtonItem can be huge and the titleView will resize and truncate to fit the available space, which is exactly how it should be, and how I want it.

However, with the same dimensions reversed (rightBarButtonItem smaller than a certain width and leftBarButtonItem huge), the leftBarButtonItem disappears entirely, and the titleView stretches to fit the entire space that previously would have held both the leftBarButtonItem and the titleView.

I tried swapping the custom views to see if it was something I had done, but the same problem persisted with the views swapped, again only on the leftBarButtonItem. I also tried using a regular title, without the custom titleView, to no avail.

In the documentation for UINavigationItem, under leftBarButtonItems, it notes that "If there is not enough room to display all of the items in the array, those that would overlap the title view (if present) or the buttons on the right side of the bar are not displayed." However, there should be more than enough room to fit both buttons and the title, as demonstrated by having a huge rightBarButtonItem and a truncated title. Not to mention, there is only a single leftBarButtonItem, not multiple, and I need it to appear to replace the back button functionality.

Any ideas on how to stop this from happening? Here's a snippet of the code I'm using:

self.navigationItem.titleView = [[TitleView alloc] initWithFrame:CGRectMake(0, 0, 220, 44)];
self.navigationItem.titleView.backgroundColor=[UIColor clearColor];

FollowButton *follow = [[FollowButton alloc] initWithFrame:CGRectMake(0, 0, 62, 34)];
UIBarButtonItem *followButton = [[UIBarButtonItem alloc] initWithCustomView:follow];
self.navigationItem.rightBarButtonItem = followButton;

BackButton *back = [[BackButton alloc] initWithFrame:CGRectMake(0, 0, 108, 34)];
[back addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:back];
self.navigationItem.leftBarButtonItem = backButton;
4

2 回答 2

1

使抗压优先级更高BackButton

于 2018-07-12T19:40:59.037 回答
0

你能检查标题栏按钮的宽度吗?它实际上是缩小还是 x 位置只是改变并被推离屏幕......如果宽度实际上变为“0”,那么您应该能够在加载后强制将其设置回所需的宽度其他按钮完成。

于 2013-01-08T05:49:07.330 回答