Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I stop leftBarButtonItem from disappearing when navigationItem.titleView and rightBarButtonItem take up most of the UINavigationBar?
    primarykey
    data
    text
    <p>Here's my predicament. Bare with me as I'm a bit of a noob when it comes to Objective-C and iOS programming. I've got a <code>leftBarButtonItem</code> (using a custom view) that's acting as a replacement for a back button (as custom views can't be used on <code>backBarButtonItem</code>). I've also got a <code>rightBarButtonItem</code> (also using a custom view) and a custom titleView.</p> <p>Everything works fine and dandy when the <code>leftBarButtonItem</code> is smaller than a certain width. The <code>rightBarButtonItem</code> 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.</p> <p>However, with the same dimensions reversed (<code>rightBarButtonItem</code> smaller than a certain width and <code>leftBarButtonItem</code> huge), the <code>leftBarButtonItem</code> disappears entirely, and the <code>titleView</code> stretches to fit the entire space that previously would have held both the <code>leftBarButtonItem</code> and the <code>titleView</code>.</p> <p>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 <code>leftBarButtonItem</code>. I also tried using a regular title, without the custom <code>titleView</code>, to no avail.</p> <p>In the documentation for <code>UINavigationItem</code>, under <code>leftBarButtonItems</code>, 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 <code>rightBarButtonItem</code> and a truncated title. Not to mention, there is only a single <code>leftBarButtonItem</code>, not multiple, and I need it to appear to replace the back button functionality.</p> <p>Any ideas on how to stop this from happening? Here's a snippet of the code I'm using:</p> <pre><code>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; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload