代码之家  ›  专栏  ›  技术社区  ›  armnotstrong

无法使用目标c更改uitoolbar的高度

  •  0
  • armnotstrong  · 技术社区  · 7 年前

    我已成功添加一个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];
    }
    

    • [self navigationController].toolbarItems 项目将不会显示

    • [self navigationController]

    所以我的问题是,我如何修改boolbar的高度,以及 self.toolbarItems [自导航控制器]。工具栏项目 ? 谢谢

    2 回复  |  直到 7 年前
        1
  •  1
  •   Abdelahad Darwish    7 年前

    NS_CLASS_AVAILABLE_IOS(2_0) @interface UINavigationController : UIViewController
    

    为了增加高度,我认为您不能将其子类化并更改intrinsicContentSize或sizeThatFits

    可以将UIView和ad创建为子视图

        2
  •  0
  •   EddgaPo    7 年前

    根据 documentation

    您可以使用 setToolbarItems:animated: UIViewController