ios - 从 Interface Builder 设置自定义 UINavigationBar 类

标签 ios uinavigationcontroller storyboard uikit uinavigationbar

我想要一个自定义 UINavigationController 子类,它有一个自定义 UINavigationBar 类作为其导航栏,但它需要是可以从 Storyboard设置的东西。

除了以 navigationBarClass 作为参数的 init 函数之外,我没有看到任何其他方法可以在 UINavigationController 上设置 navigationBarClass(即使是子类化的),但这将忽略 nib 属性和 rootViewController (并崩溃)。

class CustomNavigationController : UINavigationController {
  override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
      //This clearly doesn't work because it will not account for the styling, 
      // attributes, and rootViewController applied from the nib
      super.init(navigationBarClass: CustomNavigationBar, toolbarClass: nil)

  }
}

有办法解决这个问题吗?或者我可以假设没有办法在 Storyboard中使用自定义导航栏类​​吗?

最佳答案

在 IB 中,打开导航 Controller ,然后在左侧列表中选择“导航栏”: Navigation Controller element list

在右侧的检查器中,更改自定义类: Navigation Bar Inspector

关于ios - 从 Interface Builder 设置自定义 UINavigationBar 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49262608/

相关文章:

ios - NSDateFormatter中的问题将NSDate转换为字符串

ios - 替代私有(private)-[UIDevice setOrientation :] for forcing camera overlay into portrait mode

ios - 需要状态栏中的小事件指示器,类似于 WhatsApp

objective-c - 应用程序中的多个导航 Controller

ios - 为什么我不能在 Swift 中设置我的 UINavigationController 的标题?

ios - 仅发生在 AppStore 上 - 致命异常 : NSInternalInconsistencyException Could not load NIB in bundle

iphone - Objective C/iPhone 应用程序中的直方图生命周期数据类型

ios - 导航栏上的按钮不拾取窗口色调颜色

ios - 我如何将内容置于 View Controller 的中心,以便无论 xamarin Storyboard 中使用什么设备尺寸,它始终居中?

ios - 在 Storyboard 中的两个场景之间传输图像