Custom UINavigationController UINavigationBar

后端 未结 4 1620
眼角桃花
眼角桃花 2021-02-02 04:24

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

4条回答
  •  别那么骄傲
    2021-02-02 04:56

    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.

提交回复
热议问题