【问题标题】:How do I calculate the optimal titleView width?如何计算最佳 titleView 宽度?
【发布时间】:2009-08-06 23:15:51
【问题描述】:

我正在使用带有自定义UIView 子类的导航,该子类成为我的titleView。我想确保这是完整的可用宽度。

从我的UIViewControllerviewWillAppear: 看来,这应该是:

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

(我这里没有合适的项目。)

然后,这将适应leftBarButtonItem 的不同可能宽度。问题是leftBarButtonItemnil,所以leftBarButtonItem.width 始终为0(好吧,无论如何在模拟器中)。

backBarButtonItem 也为零。

我应该怎么做?

【问题讨论】:

  • 我也有这个确切的问题:(

标签: iphone uinavigationcontroller uinavigationbar uibarbuttonitem uinavigationitem


【解决方案1】:

我通过以下操作破解了这个:

    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;

讨厌,但它有效

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 1970-01-01
    • 2021-12-03
    • 2017-10-28
    相关资源
    最近更新 更多