首页 文章

在Fox新闻iPhone应用程序中自定义UINavigationBar

提问于
浏览
1

如何完成UINavigationBar自定义?它是使用子类还是类别?

Fox news iphone app

我对两个方面感兴趣:

  • 将图像添加到导航栏(如FOXNEWS徽标)

  • 自定义后退按钮为"Shows" . (后退按钮通常采用堆栈中前一个视图的 Headers ,但在上一个视图中没有 Headers . )

在此先感谢您的帮助

2 回答

  • 7

    对于福克斯新闻应用程序,它看起来只是设置导航栏的色调颜色 . 至于福克斯新闻标志,它是's probably just an image view on the title view of the navigation bar. This code goes into a view controller' s viewDidLoad 方法:

    [self.navigationController.navigationBar setTintColor:/* Custom color here */];
    
    UIImageView *logoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo"]];
    [self.navigationItem setTitleView:logoView];
    [logoView release];
    

    要自定义后退按钮,您需要将其放在上一个视图控制器的 viewDidLoad 方法中(即此按钮返回的方法):

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Shows"
        style:UIBarButtonItemStyleBordered target:nil action:nil];
    [self.navigationItem setBackBarButtonItem:backButton];
    [backButton release];
    

    如果要为应用程序的导航栏使用完全自定义的背景图像,则需要创建自定义 UINavigationBar 类别并在其 drawRect: 方法中绘制图像 . 像这样的东西:

    @implementation UINavigationBar (UINavigationBarBackgroundImage)
    
    - (void)drawRect:(CGRect)rect
    {
        [[UIImage imageNamed:@"navigation-bar"] drawInRect:rect];
    
        // Optionally you can set the tintColor here to go with the background
    }
    
    @end
    
  • 0

    将图像添加到导航栏使用此代码

    - (void)drawRect:(CGRect)rect {
    
    UIColor *color = [UIColor blackColor]; //this use to set button color in FoxNew Site //button color
    UIImage *img  = [UIImage imageNamed: @"ImageName"];
    [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    self.tintColor = color;
    
    }
    

    为UINavigationBar创建类别

    @implementation UINavigationBar (UINavigationBarCategory)
        - (void)drawRect:(CGRect)rect {
         }
    
    @end
    

相关问题