Reputation: 9082
Since iOS 5 it is easy to customize the background image of UINavigationBar
, but it seems that there is something that I am missing when it comes to setting the background image for MFMailComposeViewController
. I use the following snippet to set up an instance of MFMailComposeViewController
.
if ([MFMailComposeViewController canSendMail])) {
// Initialization
MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];
[vc setModalPresentationStyle:UIModalPresentationFormSheet];
// Navigation Bar
[[vc navigationBar] setBackgroundImage:[UIImage imageNamed:@"navbar_top"] forBarMetrics:UIBarMetricsDefault];
// Configuration
[vc setMailComposeDelegate:self];
// Present Mail Compose View Controller
[self presentViewController:vc animated:YES completion:nil];
}
While the bar button items are properly skinned, the navigation bar of the mail compose view controller is not. Am I overlooking something?
Upvotes: 0
Views: 2931
Reputation: 21
Just add some code in your "myAppDelegate.m" as follows:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"blueBarBG.png"] forBarMetrics:UIBarMetricsDefault];
...
}
Hope it will help you
Upvotes: 2
Reputation: 1540
after u present the controller
// Present Mail Compose View Controller
[self presentViewController:vc animated:YES completion:nil];
add the image as an imageView like this
UIImage *image = [UIImage imageNamed: @"navbar_top.png"];
UIImageView * iv = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,42)];
iv.image = image;
iv.contentMode = UIViewContentModeCenter;
[[[vc viewControllers] lastObject] navigationItem].titleView = iv;
[[vc navigationBar] sendSubviewToBack:iv];
[iv release];
but I believe there is some kind of protection that came with iOS4.
It is clearly stated here that you MUST NOT change the interface provided by Apple.
Important: The mail composition interface itself is not customizable and must not be modified by your application. In addition, after presenting the interface, your application is not allowed to make further changes to the email content. The user may still edit the content using the interface, but programmatic changes are ignored. Thus, you must set the values of content fields before presenting the interface.
i have searched the forums and some have got their app rejected, so i guess u should refrain urself from doing this.
hope it helps. happy coding :)
Upvotes: 0
Reputation: 1920
You can do this because MFMailComposeViewController class inherited from
UINavigationController : UIViewController : UIResponder : NSObject
But go through the apple documentation. Apple wont allow to do so.
Important
The mail composition interface itself is not customizable and must not be modified by your application. In addition, after presenting the interface, your application is not allowed to make further changes to the email content. The user may still edit the content using the interface, but programmatic changes are ignored. Thus, you must set the values of content fields before presenting the interface.
FOR MORE INFORMATION MFMailComposeViewController_class
If you still want to implement then this might help you changing-the-navigation-bar-with-MFMailComposeViewController
Upvotes: 0
Reputation: 38239
EDIT : refer custom-background-for-uinavigationbar link.
I think u might have given wrong image name: navbar_top it might be navbar_top.png or navbar_top.jpg
U can try this:
if([[UINavigationBar class] respondsToSelector:@selector(appearance)]) //iOS >=5.0
{
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar_top.png"] forBarMetrics:UIBarMetricsDefault];
}
Upvotes: 0