无法使用 objective c 更改 uitoolbar 的高度

Can't change the height of uitoolbar with objective c

我已经使用以下代码成功添加了一个 UIToolBar:

-(void) setUpBottom{

    UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIBarButtonItem *feature = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"features.png"] style:UIBarButtonItemStylePlain target:self action:@selector(selectFeature:)];

    UIBarButtonItem *fav = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"favorite-outline.png"] style:UIBarButtonItemStylePlain target:self action:@selector(selectFavorite:)];

    //following line was intended to change the height of the tool bar, but it doesn't work.
    [[self navigationController].toolbar setFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - 55, [[UIScreen mainScreen] bounds].size.width, 55)];

    self.toolbarItems = [NSArray arrayWithObjects:flexible,feature, flexible,fav,flexible,nil];
    [[self navigationController] setToolbarHidden:NO];
}

让我感到奇怪的是:

所以我的问题是如何修改boolbar的高度,更重要的是,self.toolbarItems[self navigationController].toolbarItems的关系是什么?谢谢。

UINavigationController 的 ToolbarItems 属性 对其自身的工具栏没有影响。

NS_CLASS_AVAILABLE_IOS(2_0) @interface UINavigationController : UIViewController

您应该注意,它是从 UIViewController 继承而来的,并且仅当您将该导航控制器放入另一个导航控制器时才有效。

增加高度我认为你不能将它子类化并更改 intrinsicContentSize 或 sizeThatFits

您可以创建 UIView 和广告作为子视图

根据documentation

您可以使用 UIViewController

setToolbarItems:animated: 方法分配一组自定义工具栏项

但我不确定你是否可以更改内置工具栏的高度