Set a custom subclass of UINavigationBar in UINavigationController programmatically

前端 未结 12 1519
清歌不尽
清歌不尽 2020-11-28 17:29

Does anyone know how can I use my custom subclass of UINavigationBar if I instantiate UINavigationController programmatically (without IB)?

<
12条回答
  •  醉梦人生
    2020-11-28 18:13

    Since iOS5, apple provides a method to do this directly. Reference

    UINavigationController *navigationController= [[UINavigationController alloc]initWithNavigationBarClass:[CustomNavBar class] toolbarClass:nil];
    [navigationController setViewControllers:[NSArray arrayWithObject:yourRootViewController]];
    

提交回复
热议问题