Despite globally altering your UINavigationBar title through the appearance proxy such as this:
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:0.5 forBarMetrics:UIBarMetricsDefault];
How can you define the title's vertical height for a single view controller which I would expect to look like this:
[self.navigationBar setTitleVerticalPositionAdjustment:0.5 forBarMetrics:UIBarMetricsDefault];
But unfortunately does not work. I am trying to adjust my titles' vertical position for a specific view controller without affecting the other view controllers' UINavigationBar title position.
You could use the appearanceWhenContainedIn:
selector to set the appearance for each individual UIViewController. It would look something like this...
[[UINavigationBar appearanceWhenContainedIn:[ViewControllerOne class], nil] setTitleVerticalPositionAdjustment:0.3 forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[ViewControllerTwo class], nil] setTitleVerticalPositionAdjustment:0.5 forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[ViewControllerThree class], nil] setTitleVerticalPositionAdjustment:0.7 forBarMetrics:UIBarMetricsDefault];
Update:
Example of how to use this by creating a StyleManager
class:
@implementation StyleManager
+ (void)setApplicationStyle
{
[[UINavigationBar appearanceWhenContainedIn:[ViewControllerOne class], nil] setTitleVerticalPositionAdjustment:0.3 forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[ViewControllerTwo class], nil] setTitleVerticalPositionAdjustment:0.5 forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[ViewControllerThree class], nil] setTitleVerticalPositionAdjustment:0.7 forBarMetrics:UIBarMetricsDefault];
// Other appearnce styling here...
}
@end
Once you've created your StyleManager
you can simply use it in your AppDelegate
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[StyleManager setApplicationStyle];
}
Let me know if this works for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.