How do I change the color of the MFMessageComposeViewController elements? - ios

I set up and open my MFMessageComposeViewController with the following:
- (void)openSMSViewWithRecipientsArray:(NSArray *)recipients {
MFMessageComposeViewController *messageVC = [MFMessageComposeViewController new];
if([MFMessageComposeViewController canSendText]){
messageVC.body = #"";
[[messageVC navigationBar] setTintColor:[UIColor whiteColor]];
messageVC.recipients = recipients;
messageVC.messageComposeDelegate = self;
[self presentViewController:messageVC animated:YES completion:nil];
}
}
But the screen looks like this:
So how do I change either the purple background where the numbers are, or change the number colors along with the plus sign color?

I couldn't change only the purple background where the numbers were, so I had to change the whole nav bar color so it would apply to the background of the numbers:
- (void)setNavBarColor:(UIColor *)navBarColor titleColor:(UIColor *)titleColor {
[[UINavigationBar appearance] setBarTintColor:navBarColor];
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"Futura-Medium" size:17.0f],
UITextAttributeFont,
titleColor,
UITextAttributeTextColor,
nil]];
}

Related

How to change color of navigation bar in mfmessagecomposeviewcontroller while presenting it in ios 9

MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc]init];
[UINavigationBar appearance].barTintColor = [UIColor colorWithRed:0.0f/255.0f green:127.0f/255.0f blue:254.0f/255.0f alpha:1.0];
[[messageController navigationBar] setTintColor: [UIColor whiteColor]];
messageController.messageComposeDelegate = self;
[messageController setBody:message];
[messageController navigationBar].translucent =NO;
[messageController.navigationBar setBarTintColor:[UIColor colorWithRed:0.0f/255.0f green:127.0f/255.0f blue:254.0f/255.0f alpha:1.0]];
// Present message view controller on screen
[self presentViewController:messageController animated:YES completion:^{
[messageController navigationBar].translucent = NO;
}];
I have been using this code. Please let me know if anything is missing.
You just need to add two lines to change navigation bar color.
For MFMailComposeViewController.
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
[mc.navigationBar setTintColor:[UIColor whiteColor]];//cancel button will be of white color.
[mc.navigationBar setBarTintColor:[UIColor blackColor]];//bar color will be black.
if (mc != nil)
{
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:bodyText isHTML:YES];
[mc setToRecipients:toRecipents];
[self presentViewController:mc animated:YES completion:nil];
}
For MFMessageComposeViewController
Create one method like below for changing navigation bar color.
- (void)setNavBarColor:(UIColor *)navBarColor titleColor:(UIColor *)titleColor {
[[UINavigationBar appearance] setBarTintColor:navBarColor];
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"Futura-Medium" size:17.0f],
UITextAttributeFont,
titleColor,
UITextAttributeTextColor,
nil]];
}
And write this method before you initialise MFMessageComposeViewController.(This is very important otherwise it will not work)
This code work for me in ios 9.
May be it will help you.
I tried the edit with the solution mentioned up above and it didn't quite work. However, I found a solution with some help. My solution worked with a build target of iOS12.1+ and I tested it on iOS15.4:
MFMessageComposeViewController *messageController = [MFMessageComposeViewController new];
[messageController.navigationBar setBarTintColor: [UIColor redColor]];
[self presentViewController:messageController animated:true completion:nil];
[UIView appearanceWhenContainedInInstancesOfClasses:[NSArray arrayWithObject:[MFMessageComposeViewController class]]].tintColor = [UIColor redColor];
MFMessageComposeViewController: Cannot Style "Cancel" Button in Dark Mode

MFMailComposeViewController bar background color not changing in iOS7

I'm trying to change the background color of the MFMailComposeViewController in iOS7 but I cannot make it work.
I'm using the following snipped:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
if([picker.navigationBar respondsToSelector:#selector(barTintColor)]) {
// iOS7
picker.navigationBar.barTintColor = READER_NAVIGATION_BAR_BACKGROUND_COLOR;
// Set back button arrow color
[picker.navigationBar setTintColor:READER_NAVIGATION_BAR_BACK_BUTTON_ARROW_COLOR];
// Set Navigation Bar Title Color
[picker.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:READER_NAVIGATION_BAR_TITLE_NORMAL_FONT_COLOR forKey:UITextAttributeTextColor]];
// Set back button color
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:READER_NAVIGATION_BAR_BUTTONS_FONT_COLOR, UITextAttributeTextColor,nil] forState:UIControlStateNormal];
}
Does anybody knows how to change the bakcground color of the MFMailComposeViewController in iOS7?
The trick here is to call 'appearance methods' such as
[UINavigationBar appearance].barTintColor = [UIColor whiteColor];
[UINavigationBar appearance].tintColor = [UIColor redColor];
BEFORE calling to
[[MFMailComposeViewController alloc] init];
This way the color scheme will be applied to the mail composer.
It may be returned back to defaults in mailComposeController:didFinishWithResult:
try this. worked for me.
MFMailComposeViewController* myailViewController = [[MFMailComposeViewController alloc] init];
// set other attributes of mailcomposer here.
myMailViewController.mailComposeDelegate = self;
[myMailViewController.navigationBar setTintColor:[UIColor whiteColor]];
[self presentViewController:myMmailViewController animated:YES completion:nil];
Swift 3 solution:
extension MFMailComposeViewController {
override open func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
}
open override func viewDidLoad() {
super.viewDidLoad()
navigationBar.isTranslucent = false
navigationBar.isOpaque = false
navigationBar.barTintColor = UIColor.white
navigationBar.tintColor = UIColor.white
}
}
For iOS8:
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],UITextAttributeTextColor,
[UIColor blackColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(-1, 0)], UITextAttributeTextShadowOffset, nil];
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
Or
navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor yellowColor] forKey:UITextAttributeTextColor];
try this but one thing BarTintColor available only iOS7
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
This color is made translucent by default unless you set the translucent property to NO.
or try this link it will more helpful you
Changing MFMailComposeViewController's toolbar color
Try the following code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setBackgroundColor:[UIColor blackColor]];
// Your usual code follows here ......
#SoftDesigner's answer:
As of iOS 9:
[UINavigationBar appearance].tintColor = yourFavoriteColor;
does not work on the MFMailComposeViewController.
The rest of the answer works (I used it), but as far as I can tell you're stuck with Apple's colors for the nav bar buttons.
Hope this saves someone else some angst.
First present the MFMailComposeViewController then change its tintColor
[self presentViewController:emailDialog animated:TRUE completion:nil];
[[UINavigationBar appearance] setBackgroundImage:nil
forBarPosition:UIBarPositionTopAttached
barMetrics:UIBarMetricsDefault];
I had a problem that prevented me from setting the background colour. Turns out I had some other code elsewhere setting the background image to [UIImage new].
The following code fixed it:
[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:nil];

MFMailComposeViewController appearance setTintColor getting lost iOS 7

This question is for Xcode 5 running iOS 7 and is super weird. I am trying to set all the UInavigation and UIBarButtonItem text colors to white.
So in my app launch delegate I set the code as.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIImage *NavigationPortraitBackground = [UIImage imageNamed:#"button_header_blue"];
// Set the background image all UINavigationBars
[[UINavigationBar appearance] setBackgroundImage:NavigationPortraitBackground forBarMetrics:UIBarMetricsDefault];
// Set the text appearance for navbar
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor whiteColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"Helvetica Neue" size:21], UITextAttributeFont,
nil]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],
UITextAttributeTextColor,
[UIColor whiteColor],
UITextAttributeTextShadowColor,
nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState: UIControlStateNormal];
[[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
// Override point for customization after application launch.
return YES;
}
If I launch "send mail" action twice
- first time I see UIBarButton items white. I look at it and hit the Cancel button
- second time I see them all of them grayed out and barely visible except for the title.
- This is happening in both my iPhone simulator and iPhone running iOS 7.
how can I fix this?
I had to do it this way in order for it to work on iOS 7
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController.navigationBar setTintColor:[UIColor whiteColor]];
[mailViewController.navigationBar setBarTintColor:[UIColor whiteColor]];
....

iOS 7 UINavigationBar appearance not working first timeā€¦

I am trying to change the look of the UINavigationBar in my iOS7 app. I am doing the following:
- (void)viewDidLoad
{
[super viewDidLoad];
m_sNumberToCall = #"";
UIBarButtonItem * btn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"IconHome.png"] style:UIBarButtonItemStyleBordered target:self action:#selector(btHomeTouched:)];
self.navigationItem.leftBarButtonItem = btn;
self.navigationController.navigationBar.translucent = YES;
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"TVCNavBack.png"] forBarMetrics:UIBarMetricsDefault];
NSShadow * shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0],
NSForegroundColorAttributeName,
shadow,
NSShadowAttributeName,
[UIFont fontWithName:#"Helvetica-Bold" size:21.0],
NSFontAttributeName,
nil]];
}
But, the first time I present the UITableViewController it is the standard iOS7 nav bar, then I press home and present it again and it is my new look.
Any ideas why it does not work the first time?
Don't change the appearance but the navigation bar directly. The appearance affects only the future instances but not the already created ones.
Change:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"TVCNavBack.png"] forBarMetrics:UIBarMetricsDefault];
to:
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"TVCNavBack.png"] forBarMetrics:UIBarMetricsDefault];
The answer before only helps you with the background image but not with the title text attributes.
You don't need to change your code but all you have to do is move it to
applicationDidFinishLaunchingWithOptions
in your AppDelegate.m file.

Change single navigation bar color for total app

I have using two UINavigationBar's in my app ,now am applying themes to my app i'm trying to change navigation bar color of the total app using this line of code
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
am getting two navigation bars with black color is there any way to change single navigation bar color for total app
Instead of [UINavigationBar appearance] you can use [UINavigationBar appearanceWhenContainedIn:...] to be more specific about which UINavigationBars are changed based on their context.
For example you could create a subclass of UINavigationController called MyNavigationController (no need to add any behaviour) then do:
[[UINavigationBar appearanceWhenContainedIn:[MyNavigationController class], nil] setTintColor:[UIColor blackColor]];
Only UINavigationBars that live within your subclass will have their appearance changed.
I've used this idea in an iPad app where I wanted UINavigationBars that appeared within modal FormSheets to look different to other UINavigationBars within the app for example.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
if(isiPhone5)
{
self.LoadinFirst = [[LoadingFirstViewController alloc] initWithNibName:#"LoadingFirstView-iPhone5" bundle:nil];
}
else {
self.LoadinFirst = [[LoadingFirstViewController alloc] initWithNibName:#"LoadingFirstView" bundle:nil];
}
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.LoadinFirst];
[navigationController.navigationBar setBarStyle:UIBarStyleBlack];
[navigationController.navigationBar setTintColor:[UIColor colorWithRed:192/255.00f green:182/255.00f blue:184/255.00f alpha:1.0f]];
self.window.rootViewController =navigationController;
[self.window makeKeyAndVisible];
return YES;
}
If you want to put an image in the navigation bar with the color you want you can use
if ([self.navigationController.navigationBar respondsToSelector:#selector(setBackgroundImage:forBarMetrics:)] )
{
UIImage *image = [UIImage imageNamed:#"titlebg.png"] ;
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
else you can easilt set the tint by using
[navigationController.navigationBar setTintColor:[UIColor colorWithRed:102/255.00f green:182/255.00f blue:114/255.00f alpha:1.0f]];
hope this helps.
To change the over all navigation bar color you can use the method
[[UINavigationBar appearance] setBackgroundColor:[UIColor blueColor]];
To change the overall font and such you can use something like :
-(void) changeNavigationBarStyle{
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
UITextAttributeTextColor,
[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.8f],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"ChalkboardSE-Bold" size:0.0],
UITextAttributeFont,
nil]];
NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary: [[UIBarButtonItem appearance] titleTextAttributesForState:UIControlStateNormal]];
[attributes setValue:[UIFont fontWithName:#"ChalkboardSE-Bold" size:0.0f] forKey:UITextAttributeFont];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
}
EDIT DUE TO COMMENTS
To change the color (blue in this example) of all UINavigationBars in the application you can call
[[UINavigationBar appearance] setBackgroundColor:[UIColor blueColor]];
To change the color of one UINavigationBar you can call
self.navigationController.navigationBar.tintColor = [UIColor blueColor];
There is no middle ground where you can say "Change all UINavigationBar's color except ..."

Resources