Override Uiappearance Property for Mfmailcomposeviewcontroller

Override UIAppearance property for MFMailComposeViewController

Changing the appearance of a MFMailComposer through normal measures is not possible, but there is a little workaround you can do, which I've used many times before.

Add two methods to the class in which you wish to implement the new look to:

- (void)applyComposerInterfaceAppearance
{
[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
}

- (void)applyGlobalInterfaceAppearance
{
// My default color of choice
[[UINavigationBar appearance] setTintColor:[UIColor redColor]];
}

Now in your show method, apply the special composer interface changes you'd like to make.

- (void)showMailComposer
{
if ([MFMailComposeViewController canSendMail])
{
[self applyComposerInterfaceApperance];

MFMailComposeViewController *viewController = [[MFMailComposeViewController alloc] init];
viewController.mailComposeDelegate = delegate;
[viewController setToRecipients:mailRecepients];
[viewController setSubject:mailSubject];
[viewController setMessageBody:messageBody isHTML:NO];
[self presentModalViewController:viewController animated:YES];
}
}

And in your delegate, change the interface back to the way it was.

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
// Do normal mail composer did finish stuff in here
[self applyGlobalInterfaceAppearance];
}

UIAppearance Remove Custom NavBar Background for UIPopoverController

Try using the +appearanceWhenContainedIn: method to remove your background-image customization from navigation bars when they’re contained in popover controllers. Something like this:

[[UINavigationBar appearanceWhenContainedIn:[UIPopoverController class], nil] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];

It’s not clear from the documentation whether setting a navigation bar’s background image to nil restores its default appearance—if that doesn’t work, you might have to take the opposite approach, and provide the list of non-popover container view controllers you’re using to +appearanceWhenContainedIn:.

MFMailComposeViewController crashing on presentViewController on iOS 10.2

Strange! My guess here is that you have set something (a font?) badly via UIAppearance and the mail composer is the first time this appearance property is being referenced. Does your project use UIAppearance (e.g. UINavigationBar.appearance)? If so, comment them out for now. See if that fixes the problem, then figure out which call is the culprit.

Mail Compose View Controller Navigation Bar

The appearance proxy enables you to modify the appearance of the UI when it's contained in a specific class through the -appearanceWhenContainedIn method. You can set the image to nil to prevent it from being shown in the MFMailComposeViewController class as shown below.
[[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];

According to this question, you need to change the appearance proxy before and after you present the modal MFMailComposeViewController in order to change its appearance back to how it was.

Override UIAppearance property for MFMailComposeViewController

UIPageControl + UIAppearance

UIAppearance protocol was added to UIPageControl as of iOS 6.

The properties you can customise are:

  • Dot tint colour
  • Highlighted dot tint colour

This is an excerpt from UIPageControl.h, as you can see these UIAppearance additions are only available from iOS 6.

@property(nonatomic,retain) UIColor *pageIndicatorTintColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
@property(nonatomic,retain) UIColor *currentPageIndicatorTintColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;

UIAppearance and UINavigationBar controller

Apparently UIBarButtonItem has a separate function for the backbutton customization. I had to create another image for the back button based off navbar_btn.png and set it using:

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

iOS 5: Curious about UIAppearance

a) How do I know which instances of a class work with the appearance property? For e.g. since UITableView conforms to the UIAppearance protocol I was thinking I could do something like

You look in the header of the class (and the headers of all the superclasses). Any method that has UI_APPEARANCE_SELECTOR next to it is supported for use with the UIAppearance proxy.

[[UITableView appearance] setBackgroundColor:mytableViewColor];

The backgroundColor property is not decorated with UI_APPEARANCE_SELECTOR in UIView.h. Thus it is not technically supported for use with the appearance proxy. It will probably work, but (given the lack of method decoration) isn't guaranteed to.

From the UIAppearance Protocol Reference:

To support appearance customization, a class must conform to the UIAppearanceContainer protocol and relevant accessor methods must be marked with UI_APPEARANCE_SELECTOR.

(note "and relevant accessor methods must be marked..." [emphasis added])


b) Is there a list of all properties that are manipulatable with the appearance property?

Is there a single page showing every setter that works with the appearance proxy? I don't know of one, nor is there a way to build the list at runtime.


c) At what point is the appearance customization being called? I was hoping to make changes threw the appearance property at runtime, but unfortunately the changes aren't taking place.

You can use the appearance proxy at any point during execution. The changes won't be applied to the affected views until the next time those views have their -layoutSubviews method invoked.

MFMailComposeViewController navigationBar

Using the standard apple MFMailComposeViewController you can't, to put it simply. You would normally present it modally so it would go completely over your view anyway.

If you wanted a custom looking compose sheet, you would have to create it as a custom controller with a custom view. You would also need either a mail server built into your app, or a server that you can hit to send the mail for you.

For security reasons apple limit what you can do with MFMailComposeViewController.

If I can be of more help, please do ask :)



Related Topics



Leave a reply



Submit