gpt4 book ai didi

ios - 如何创建像 BestBuy App 这样的自定义导航栏?

转载 作者:可可西里 更新时间:2023-11-01 03:37:52 25 4
gpt4 key购买 nike

我想制作一个自定义导航栏,就像在 BestBuy 应用程序中一样,或者像下面给定的屏幕截图所示。

enter image description here

我希望这种类型的导航始终位于每个 viewController 的顶部。

如果有人能告诉我程序或任何类型的帮助,我们将不胜感激。谢谢。

最佳答案

编写 UINavigationBar 的子类,您可以在其中自定义绘图并根据需要添加 subview 。

然后通过使用 initWithNavigationBarClass:toolBarClass:

初始化它来告诉您的 navigationController 使用该类

例如

@interface MyBar : UINavigationBar
@end

@implementation MyBar
.... //like any UIView
@end

UINavigationController *navi = [[UINavigationController alloc] initWithNavigationBarClass:[MyBar class] toolbarClass:nil];

代替 initWithRootViewController


示例

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.mainViewController = [[FDMainViewController alloc] initWithNibName:@"FDMainViewController_iPhone" bundle:nil];
} else {
self.mainViewController = [[FDMainViewController alloc] initWithNibName:@"FDMainViewController_iPad" bundle:nil];
}

UINavigationController *navi = [[UINavigationController alloc] initWithNavigationBarClass:[UINavigationBar class] toolbarClass:nil];
navi.viewControllers = @[self.mainViewController];
self.window.rootViewController = navi;
[self.window makeKeyAndVisible];
return YES;
}

关于ios - 如何创建像 BestBuy App 这样的自定义导航栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14747665/

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