Custom UINavigationController UINavigationBar

一笑奈何 提交于 2019-12-03 06:25:28

问题


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:

Any ideas how to achieve this at all?

Thanks


回答1:


@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.




回答2:


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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/4042108/custom-uinavigationcontroller-uinavigationbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!