How to calculate the optimal header width?

I use navigation with a custom subclass UIViewthat becomes my titleView. I want it to be the full width available.

Logically from mine UIViewController viewWillAppear:, this should be:

CGFloat width = self.width - self.navigationItem.leftBarButtonItem.width - someConstant;

(There is no required item here.)

This would then adapt to various possible widths leftBarButtonItem. The trap is that it leftBarButtonItemis equal nil, therefore leftBarButtonItem.widthalways 0 (well, in any case, in the simulator).

backBarButtonItem also equal to zero.

What should I do instead?

+5
source share
1 answer

, :

    int vcStackSize = [[self.navigationController viewControllers] count];
    WEViewController* previousController = [[self.navigationController viewControllers] objectAtIndex:vcStackSize - 2];

    NSString* previousTitle = [previousController title];

    UIFont* font = [UIFont boldSystemFontOfSize:12];


    lw = [previousTitle sizeWithFont:font].width + 26;

,

+4

All Articles