custom UINavigationBar background in MFMailComposeViewController - iphone

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];

Related

How to change pull to refresh icon of tableview in swift? [duplicate]

I have been looking around but couldn't find anything good about this.
I would like to customize the default UIRefeshControl with different loader, etc. So far I can only change tintColor & attributedTitle properties and most code I found are just basically creating a new "pulltorefresh" effect but what I want is to just use the UIRefreshControl and customize it a bit.
Is this possible?
You can't add different loader without accessing private APIs, but you can add background image:
UIImageView *rcImageView =
[[UIImageView alloc] initWithImage:
[UIImage imageNamed: #"refreshControl.png"]];
[self.refreshControl insertSubview:rcImageView atIndex:0];
assuming self is an instance of UITableViewController subclass.
Image size you need is 320x43px (#2x 640x86px), the middle area (approximately 35px) will be covered by the loader animation.
I show application logo there...

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.

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.

how to customize navigationbar color of MFMailComposeViewController?

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.

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];