how to customize navigationbar color of MFMailComposeViewController? - iphone

from this code will show in original color how can i change it to another color?
maybe it need to be override?
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[mail setToRecipients:[NSArray arrayWithObjects:#"me#gmail.com",nil]];
[mail setSubject:#"support"];
[mail setMessageBody:#"enter your message here" isHTML:NO];
[self presentModalViewController:mail animated:YES];
}

I haven't done this so take this answer with appropriate caution.
MFMailComposeViewController inherits from UINavigationController. That means it'll have a navigationBar property. Once you have the navigationBar you can modify its tintColor property.

Actually, the iPhone SDK prohibits you from modifying the appearance MFMailComposeViewController. From the docs (here):
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.
Sorry...

As of later versions of iOS in Apple Docs you should use UIAppearance protocol
Important
You must not modify the view hierarchy presented by this view
controller. You can, however, customize the appearance of the
interface using the UIAppearance protocol.

Related

MFMessageComposeViewController Semi-Transparent Keyboard

I'm trying to initiate a MFMessageComposeViewController with a semi transparent keyboard. I would like to make it as transparent as I want, but I don't think we are allowed to do that from the reading that I've done.
How would you set the property of the UIKeyboard when you create the MFMessageComposeViewController?
Many Thanks!
You do not. From the documentation:
Important The message composition interface itself is not customizable and must not be modified by your application. In addition, after presenting the interface, your application is unable to make further changes to the SMS content. The user can edit the content using the interface, but programmatic changes are ignored. Thus, you must set the values of content fields, if desired, before presenting the interface.
You are not supposed to change this interface, since UIKeyboard is private and the textfields on this view are not accessible by you. Attempting to access and modify this textfield via the view hierarchy might get your app rejected in the app store.
Setting the keyboardAppearance property of your text field or text view to UIKeyboardAppearanceAlert will change the keyboard to the transparent keyboard.
I heard that there's only two styles available in the public API:
[textView setKeyboardAppearance:UIKeyboardAppearanceAlert];
[textView setKeyboardAppearance:UIKeyboardAppearanceDefault];
But you can use private API methods to retrieve the keyboard implementation:
id keyboardImpl = [objc_getClass("UIKeyboardImpl") sharedInstance];
And Make it less opaque,
[keyboardImpl setAlpha:0.8f];
Tint it,
UIView *tint = [[UIView alloc] initWithFrame:[keyboardImpl frame]];
[tint setBackgroundColor:[UIColor colorWithRed:0.0f green:0.0f blue:1.0f alpha:0.3f]];
[tint setUserInteractionEnabled:NO];
[[keyboardImpl superview] insertSubview:tint aboveSubview:keyboardImpl];
[tint release];
Or even flip it:
[[keyboardImpl window] setTransform:CGAffineTransformMakeScale(-1.0f, 1.0f)];
Hope it was the solution for your problem.

custom UINavigationBar background in MFMailComposeViewController

I have a need to use a custom background for the UINavigationBar in a MFMailComposeViewController. Previously I was using a category on UINavigationBar to achieve this throughout my app, but Apple specifically requests that you do not do this. Additionally this may or may not work in future versions of iOS that are currently under NDA.
I am now using a subclass of UINavigationBar to achieve the look I'm after in the rest of the app, but I can't see any way to use this with the MFMailComposeViewController. Any ideas?
Note: I'm aware of methods to do this in a future version of iOS, but this needs to be built against a current version (4.3) of the SDK.
I just ran across this -- you can dynamically inject the class a view controller uses using object_setClass.
#import <objc/runtime.h>
object_setClass(mailController.navigationBar, [YourNavigationBarSubClass class]);
You can customize the nav bar's titleView with a custom view using the code below. Expanding upon this idea, you may be able to resize the titleView to cover the entire navigation bar and use a custom background in that to simulate a custom navbar background.
The only possible sticky part I can think of is that you need to make sure the titleView sits behind the buttons in the toolbar.
Once you have your MFMailComposerViewController reference, here is the code to customize the titleView:
[self presentModalViewController:controller animated:YES];
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(//set size to navbar size)];
[backgroundView setBackgroundColor:[UIColor colorWithPatternImage://your custom image ]];
controller.topViewController.navigationItem.titleView = backgroundView ;
[controller release];
The mail composition interface itself is not customizable and must not be modified by your application.
check apple reference for more info...
http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html
but we can customizable the mail composition as given oin the above answer....
After some hacking and testing, still not manage to customize the button. But this is the closest I can get, by setting the tint color of mail controller.
Try accessing them through mailController.navigationBar.items, which is an array of the bar items.
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
mailController.navigationBar.tintColor = [UIColor brownColor];
Although it would be nice to get more control over the appearance, I don't think there is a clean method. When you cant change it...hide it:
NSDictionary *attributes = #{NSForegroundColorAttributeName: [UIColor clearColor]};
[[UINavigationBar appearance] setTitleTextAttributes:attributes];

MFMailComposer view does not suit with the color theme of my app

Does anyone know how can we send mail without presenting the MFMailComposerView?
OR
Is there any way I can add a background image on the MFMailComposerView?
I tried changing the backgroud color. it doesn't work.
Only thing i could do was change the navigationBar Tint color
Code:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
picker.navigationBar.tintColor=[UIColor blackColor];
picker.view.backgroundColor=[UIColor brownColor];
Thanks in advance!
From the apple documentation:
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 don't think it's possible, or even if possible, it would be probably rejected by AppStore.

Class to manage e-mail from iPhone

I'm working on an iPhone app that offers the user the opportunity to send an e-mail in 3 different places in the app, and for 3 different purposes.
Rather than put the same code for showing the e-mail composer in 3 different view controllers, shouldn't I develop a separate E-mail class, create an instance, and then set properties such as To, CC, BCC, Body, HTML_Or_Not, and so on?
Also, if I create an instance of such a class, and it brings up the e-mail composer, is it OK to release the class even before the e-mail composer has left the screen?
My advice, It's so easy to use the built in mail picker class, just stick with it, you can create a function to setup and show the picker, and use that when you need to like so:
- (void)showMailPicker {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
picker.navigationBar.barStyle = UIBarStyleBlack;
[picker setToRecipients: ...];
[picker setSubject:#"Title"];
// Fill out the email body text
NSString *emailBody = #"email Body...";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
Yes, it's safe to release the picker once you have presented it, and remember that once you present the picker, you can't change the email addresses, subject, body etc...
My aproach would me to encapsulate the whole process of creating, initialising, displaying, dismissing and handling all of the aspects of the mail composer in a class, like a "mail manager" or something.
Then you can create and instance and set the properties you need, and then call "show mail composer" or something to that effect.
I wouldn't recommend releasing this manager class if it will be dealing with the dismissal and handling of the result of the mail composer (ie, handling an error when sending) until after it has finished what it's doing. If you release it too early, you may not have any logical way to dismiss the mail composer or gracefully handle it's results etc.

iPhone SDK 3.0 in-app email - changing navigation bar tint color

My App uses the iPhone SDK 3.0's new in-app email feature.
I want to change the tint color of the email UI to black and make it translucent.
I tried the following code,
/*
picker.navigationController.navigationBar.tintColor = [UIColor blackColor];
picker.navigationController.navigationBar.translucent = YES ;
*/
But it's changing the color of the view that creates,
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
the compose window, rather than the compose window itself.
Is this atleast possible? Or should we stick to Apple provided blue itself???
Since the MFMailComposeViewController is a subclass of UINavigationController, simply do this:
[[picker navigationBar] setTintColor:[UIColor redColor]];
The iPhone Human Interface Guidelines do not forbid to use custom colors but recommends the standard colors (blue and black).
Yes it is possible.
Just add a objective-c category in the UINavigationBar class overriding the drawInRect Method.
This way you can do want.
The disadvantage, all your navigation bars will change :)
[[picker navigationBar] setTintColor:[UIColor blackColor]];
....makes the Cancel and Send buttons black too. They are not blue and do not change color when pressed.
You can also try this code....
MFMailComposeViewController *mailComposeView = [[MFMailComposeViewController alloc] init];
mailComposeView.navigationBar.tintColor = [UIColor cyanColor];