gpt4 book ai didi

iphone - 在 Fox news iPhone 应用程序中自定义 UINavigationBar

转载 作者:行者123 更新时间:2023-12-01 17:35:22 24 4
gpt4 key购买 nike

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

Fox news iphone app

我对2个方面感兴趣:

  • 将图像添加到导航栏(如 FOXNEWS Logo )
  • 将后退按钮自定义为“显示”。 (后退按钮通常取堆栈中前一个 View 的标题,但前一个 View 中没有标题。)

  • 提前感谢您的帮助

    最佳答案

    对于 Fox News 应用,看起来他们只是设置了导航栏的色调。至于福克斯新闻的标志,它可能只是导航栏标题 View 上的一个 ImageView 。此代码进入 View Controller 的 viewDidLoad方法:

    [self.navigationController.navigationBar setTintColor:/* Custom color here */];

    UIImageView *logoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo"]];
    [self.navigationItem setTitleView:logoView];
    [logoView release];

    要自定义后退按钮,您需要将其放在 viewDidLoad 中前一个 View Controller 的方法(即该按钮返回的那个):
    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

    关于iphone - 在 Fox news iPhone 应用程序中自定义 UINavigationBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4343329/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com