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

覆盖NavigationController的NavigationBar属性的最佳点

  •  0
  • flohei  · 技术社区  · 16 年前

    我在重写 UINavigationController 替换默认值 navigationBar 具有我自己的子类实例的属性 UINavigationBar . 所以我尝试了

    _navigationBar = [[SBNavigationBar alloc] init];
    

    在我的 -initWithRootViewController: . 但这并没有达到我的预期。还是有违约 导航栏 正在显示。

    那么覆盖 导航栏 ?

    提前谢谢
    阿夫

    1 回复  |  直到 16 年前
        1
  •  1
  •   jd291    16 年前

    如果您检查文档 http://developer.apple.com/iphone/library/documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html 你会看到 导航栏 财产是 只读的 .

    有一个习惯 navigationBar 例如,您可以使用类别。你可以在这里找到很多问题来回答这个问题。 栈溢出 .

    一个简单的版本是将图像放入 牵引器: 像这样…

    @implementation UINavigationBar (Custom)
    
    - (void)drawRect:(CGRect)rect {
        UIImage *image = [UIImage imageNamed: @"bg_toolbar.png"];
        [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    }
    
    @end