0

I have a custom method in my AppDelegate:

-(void)setupNavBar{

    UINavigationController *nav = (UINavigationController *)self.window.rootViewController;
    [nav.navigationBar setBounds:CGRectMake(0,0,320,70)];


    nav.navigationBar.translucent = YES;


    [nav.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];

    nav.navigationBar.shadowImage = [UIImage new];
    nav.navigationBar.translucent = YES;
    nav.view.backgroundColor = [UIColor clearColor];


    UIView *navBorder = [[UIView alloc] initWithFrame:CGRectMake(0, nav.navigationBar.frame.size.height-1, nav.navigationBar.frame.size.width, 1)];

    // Change the frame size to suit yours //
    [navBorder setBackgroundColor:[UIColor colorWithWhite:200.0f/255.f alpha:0.8f]];
    [navBorder setOpaque:YES];
    [nav.navigationBar addSubview:navBorder];



    CGFloat verticalOffset = 25;
    [nav.navigationBar setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
        [[UINavigationBar appearance] setTintColor:[UIColor clearColor]];

    [[UINavigationBar appearance] setTitleTextAttributes:@{
                                                        UITextAttributeTextColor: [UIColor whiteColor],
                                                        UITextAttributeFont: [UIFont fontWithName:@"Dosis-ExtraBold" size:33.0],
                                                        }];

}

I am presenting using a Nav Controller on storyboard and on the initial view controller everything looks great. However, when I push another VC (via segue) the title only half shows before the Navigationbar area seems to resize and redraw. Is there anyway to force a redraw in the ViewWillAppear so that the title text shows up whole straight away?

Have attached some images of the transition.

Thanks.

http://puu.sh/7AkJL

timss
  • 9,982
  • 4
  • 34
  • 56
  • possible duplicate of [How to fix titleView being masked to navigation bar during transition?](http://stackoverflow.com/questions/19939028/how-to-fix-titleview-being-masked-to-navigation-bar-during-transition) – Mika Mar 18 '14 at 19:12
  • I appreciate that I can put a UILabel on top of the navigation controller but this feels like a dirty fix for me? – Thalantyr Mar 18 '14 at 22:03
  • Then you will have to subclass segue and override `-(void)perform` to either increase the size of the navBar during animation or hide the title before the animation starts and show it back at the end. – Mika Mar 18 '14 at 22:48

1 Answers1

0

Try to use this:

- (void)viewDidLoad
{
    //your code 
    self.navigationItem.titleView = [self initTitle: @"IN HAND"];
}

- (UIView *)initTitle:(NSString *) titleString
{
   UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 180, 44)]; //your size!
   UILabel *navBarLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
    navBarLabel.text = titleString;
    [navBarLabel setTextAlignment:NSTextAlignmentCenter];
    navBarLabel.font = [UIFont fontWithName:@"Menlo-Regular" size:16.0f];
    navBarLabel.textColor = [UIColor whiteColor];

    [titleView addSubview:navBarLabel];
    return titleView;
}
Alex Kraev
  • 199
  • 1
  • 12
  • Thanks but it just ends up with the same result. Half appears and then it looks like it is getting redrawn as the navigation bar bounds expands? Could this be a storyboard issue? – Thalantyr Mar 18 '14 at 22:01
  • Maybe possible duplication: look here http://stackoverflow.com/questions/7779190/using-uiappearance-to-change-label-height – Alex Kraev Mar 19 '14 at 14:05