Sunday, June 9, 2013

UINavigationBar setTitleVerticalPositionAdjustment example in Objective C (iOS).


UINavigationBar setTitleVerticalPositionAdjustment

Sets the title’s vertical position adjustment for given bar metrics.

- (void)setTitleVerticalPositionAdjustment:(CGFloat)adjustment forBarMetrics:(UIBarMetrics)barMetrics

Parameters of [UINavigationBar setTitleVerticalPositionAdjustment]
adjustment
The title’s vertical position adjustment for barMetrics.
barMetrics
A bar metrics constant.

UINavigationBar setTitleVerticalPositionAdjustment example.
you can use:

[self.navigationBar setTitleVerticalPositionAdjustment:(float) forBarMetrics:UIBarMetricsDefault];
(float) being a positive value to push the titleView down, and a negative value to push the titleView up.

Example of [UINavigationBar setTitleVerticalPositionAdjustment].
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:-5.0 forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setTitleVerticalPositionAdjustment:-5.0 forBarMetrics:UIBarMetricsLandscapePhone];
   
    NSDictionary *textAttributes =  [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[UIFont fontWithName:@"MarketingScript" size:34.0], nil]
                                                                forKeys:[NSArray arrayWithObjects:UITextAttributeFont, nil]];

UINavigationBar setTitleVerticalPositionAdjustment example.
label = [[UILabel alloc] init];
label.backgroundColor = [UIColor clearColor];
label.font = [ UIFont fontWithName: @"XXII DIRTY-ARMY" size: 32.0 ];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.0f];
label.textAlignment = UITextAlignmentCenter;
label.textColor =[UIColor orangeColor];
//label.text=categoryTitle;
CGFloat verticalOffset = 2;
NSString *reqSysVer = @"5.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)          
{
    if (categoryTitle.length > 8)
    {
    label.frame = CGRectMake(0, 0, 300, 44);
    }else {
        label.frame = CGRectMake(0, 0, 80, 44);
    }

    self.navigationItem.titleView = label; 
     self.navigationItem.title=label.text;
    [[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset   forBarMetrics:UIBarMetricsDefault];
     [[UIBarButtonItem appearance] setTintColor:[UIColor newBrownLight]];

}

End of UINavigationBar setTitleVerticalPositionAdjustment example article.