Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAppearence Support for IOS 6 - unexpected results

Below code is perfectly working fine iOS 5, but not on iOS 6 or above. What I want that for Email composer sheet the navigationBar image will be different then other UINavigationBar classes. I can't understand that debug pointer is responding the appearance method but on device it shows navigationBar image as "bgNavigationBar.png"; expected is "bgNavigationBar_2.png".

Please guide me.......

if ([[UINavigationBar class]respondsToSelector:@selector(appearance)]) {
    UIImage *logoImage44 = [[UIImage imageNamed:@"bgNavigationBar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    [[UINavigationBar appearance] setBackgroundImage:logoImage44 forBarMetrics:UIBarMetricsDefault];

    UIImage *ImagePlain = [[UIImage imageNamed:@"bgNavigationBar_2.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    [[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setBackgroundImage:ImagePlain forBarMetrics:UIBarMetricsDefault];
}
like image 590
Zahur Avatar asked Jan 02 '13 16:01

Zahur


1 Answers

This thing is not working in ios6.

[[UINavigationBar appearanceWhenContainedIn:[MFMessageComposeViewController class], nil] setBackgroundImage:[UIImage imageNamed:@"bgNavigationBar_2.png"] forBarMetrics:UIBarMetricsDefault];

Just you need to set this property in your Mail Handler Class.

if (![[UINavigationBar class]respondsToSelector:@selector(appearance)])
{
    UIView *backgroundView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,320,44)]autorelease];

    [backgroundView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bgNavigationBar_2.png"]]];
    controller.topViewController.navigationItem.titleView = backgroundView ;
}
else
{
    UIImage *gradientImagePlain = [[UIImage imageNamed:@"bgNavigationBar_2.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    [[UINavigationBar appearance] setBackgroundImage:gradientImagePlain forBarMetrics:UIBarMetricsDefault];
}

and then reset another image for all other navigation controller's background image.

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self.parentController dismissModalViewControllerAnimated:YES];
    UIImage *gradientImagePlain = [[UIImage imageNamed:@"bgNavigationBar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    [[UINavigationBar appearance] setBackgroundImage:gradientImagePlain forBarMetrics:UIBarMetricsDefault];
}

Hope this will work for you.

like image 91
Nirav Jain Avatar answered Sep 21 '22 16:09

Nirav Jain