自定义 UINavigationController UINavigationBar

发布于 2024-09-29 12:12:26 字数 289 浏览 5 评论 0原文

基本上我想要一个自定义的UINavigationBar。我不希望它是“半透明”或任何东西,就像图片应用程序一样。

我基本上想完全删除它,但我仍然希望能够在推送导航控制器时添加后退按钮等,并且我希望将视图(EG:UITableViewController)推到其下方。

像这样:

alt text

有什么想法可以实现这一点吗?

谢谢

Basically I want a custom UINavigationBar. I don't want it to be "translucent" or anything, like the pictures app.

I basically want to completely remove it, but I still want to be able to add back buttons and such when navigation controllers are pushed, and I want the views (EG: UITableViewController) to be pushed down below it.

Like this:

alt text

Any ideas how to achieve this at all?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

幽蝶幻影 2024-10-06 12:12:26
@implementation UINavigationBar (background)

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

@end

基本上,它并没有完全透视——这是一个视觉谎言。实际执行此操作的唯一方法是重写 UINavigationBardrawRect: 方法,如上所示。

@implementation UINavigationBar (background)

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

@end

basically, its not completely see through - its a visual lie. The only way to do it realistically is to override UINavigationBar's drawRect: method, as shown above.

冷心人i 2024-10-06 12:12:26

要查看 UINavigationBar,如果您选择使用 UINavigationBar,只需:

self.navigationController.navigationBar.translucent=YES;

如果您希望它看起来像您发布的图像,则必须更改色调/颜色以匹配背景。

To see through the UINavigationBar, if you choose to have one, just:

self.navigationController.navigationBar.translucent=YES;

You'll have to change the tint/color to match the background if you want it to appear like the image you posted.

冷情妓 2024-10-06 12:12:26

在您的 AppDelegate 子类 UINavigationBar 的开头,如下所示:

@interface CustomNavBar : UINavigationBar

@end

@implementation CustomNavBar

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

然后在 AppDelegate 中执行此魔术:

//Set custom NavigationBar
[self.navController setValue:[[CustomNavBar alloc]init] forKeyPath:@"navigationBar"];
//Set tint to match bar.png
self.navController.navigationBar.tintColor = [UIColor colorWithRed:0.93 green:0.43 blue:0 alpha:1];
//Set font for NavigationBar
[self.navController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Comfortaa-Bold" size:20], UITextAttributeFont, nil]];

这应该给您更多的控制权UINavigationController 外观&感觉。

At the beginning of your AppDelegate subclass UINavigationBar as below:

@interface CustomNavBar : UINavigationBar

@end

@implementation CustomNavBar

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

and then in the AppDelegate do this magic:

//Set custom NavigationBar
[self.navController setValue:[[CustomNavBar alloc]init] forKeyPath:@"navigationBar"];
//Set tint to match bar.png
self.navController.navigationBar.tintColor = [UIColor colorWithRed:0.93 green:0.43 blue:0 alpha:1];
//Set font for NavigationBar
[self.navController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Comfortaa-Bold" size:20], UITextAttributeFont, nil]];

That should give you a lot more control over UINavigationController look & feel.

删除→记忆 2024-10-06 12:12:26

很难说,可能是 UINavigationBar 存在并且颜色与 UIView 背景匹配,或者没有 UINavigationBar,只是一个带有自定义按钮的视图和顶部的 UILabel 。选择一种方法并对其进行编码,或者再次提出更具体的问题。

Hard to tell, could be the UINavigationBar is there and color matches the UIView background or, there is no UINavigationBar, just a view with custom buttons and UILabel on top. Pick an approach and code it, or ask the question again with more specifics.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文