Buttons not visible on MFMailComposeViewController - ios

I have a project working with custom navigationBar. I have added the following code before the initialising MFMailComposeViewController
// Create image for navigation background - portrait
UIImage *navBar = [[UIImage imageNamed:#"HeaderStrip.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:navBar forBarMetrics:UIBarMetricsDefault];
// Create image for navigation background - landscape
UIImage *navBarL = [[UIImage imageNamed:#"HeaderStrip.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 100)];
[[UINavigationBar appearance] setBackgroundImage:navBarL forBarMetrics:UIBarMetricsLandscapePhone];
Here HeaderStrip.png is a simple red-colored image. Then in the following method, I've set the navigationBar back to original background image
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
Everything works as expected except the "Send" & "Cancel" buttons' visibility on the navigationBar of the mail composer. I've tried using tintColor before initialising MFMailComposeViewController:
[UINavigationBar appearance].tintColor = [UIColor whiteColor];
Got no difference.
I've also tried seting tintColor of the navigationBar of the composer after allocating, result same:
MFMailComposeViewController *mailer= [[MFMailComposeViewController alloc] init];
mailer.navigationBar.tintColor = [UIColor whiteColor];
Anyone got the solution of the issue? How to make the buttons visible?

Related

Nav bar is translucent, but I would like transparent

I have followed the top guides on how to make my top bar transparent, but the best I can get is translucent. I am also trying to get the buttons white, not default blue. What am I missing?
#implementation FindAssetLocationMapViewController
- (void) viewWillAppear:(BOOL)animated {
self.edgesForExtendedLayout = UIRectEdgeAll;
self.extendedLayoutIncludesOpaqueBars = true;
[self.navigationController.navigationBar setTranslucent:YES];
self.navigationController.navigationBar.shadowImage = [UIImage new];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.view.backgroundColor = [UIColor redColor];
}
Images are below. Should I take screenshots of the FindAssetLocationMapViewController attributes as well? Just to clarify, the nav controller and nav bar attributes do not have a class associated with them.
Try this code in your app delegate, then remove the code you have:
+ (UIImage *)imageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0, 0, 1, 1);
// create a 1 by 1 pixel context
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
[color setFill];
UIRectFill(rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Place this inside application:didFinishLaunchingWithOptions:
//create background images for the navigation bar
UIImage *clear = [AppDelegate imageWithColor:[UIColor clearColor]];
//customize the appearance of UINavigationBar
[[UINavigationBar appearance] setBackgroundImage:clear forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:clear forBarMetrics:UIBarMetricsCompact];
[[UINavigationBar appearance] setTranslucent:NO];
[[UINavigationBar appearance] setShadowImage:[UIImage new]];

Showing a white UINavigationBar for MFMailComposer with custom UINavigationBar themes in the app

I have a simple app which is a UITableViewController. The app uses custom themes which applies a theme to the background and the UINavigationBar. From this view, I have a UINavigationBarItem (created in code) that brings up the email sheet with MFMailComposerViewController.
I'm finding some weird behaviour with the custom themed UINavigationBar and so I just want to remove the image and have a white UINavigationBar with black buttons (cancel, send, title).
I have the code below:
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:#"PDF"];
[mailer addAttachmentData:data mimeType:#"application/pdf" fileName:fileName];
NSString *emailBody = #"Please find attached PDF";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentViewController:mailer animated:YES completion:^{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
mailer.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName : [UIColor blackColor]};
[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
[[mailer navigationBar] setTintColor:[UIColor blackColor]];
}];
}
So I am actually removing the image there. The issue is that it works, but it doesn't actually make the buttons black as they should be. Also, in some instances, there are occurrences where the custom themed UINavigationBar image shows through. I want this to never happen.
I even went as far as creating a new class which was a subclass of MFMailComposer and setting the "theme" of the UINavigationBar to be a white created bar, but that still brought about the images sometimes.
What I want is to ensure the UINavigationBar never shows an image and always has black buttons for the Cancel, Title and Send.
Any thoughts would be really appreciated.
Update
With removing the setBarTintColor and setTintColor code above, I have noticed that the first time I invoke the MFMailComposeViewController, the theme is there in the UINavigationBar, but if I close that view, and re-open it, then the image is removed and the UINavigationBar is white. How can I get this to show up as white always, without a theme? I have also removed the code that removes the images to outside of the completion block, but that didn't make a difference.
To fill UINavigationBar with color you can use backgroundImage property with blank shadow image:
[[UINavigationBar appearance] setBackgroundImage:[self imageWithColor:[UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
-imageWithColor is an additional method for creating UIImage with selected color:
- (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Then set black text color and black status bar so it will be visible:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor blackColor]}];
And don't forget that these properties will be applied to every navigation bar.
Hope it helps! :)

How to add Background image for Custom UIToolBar

i am using below code to add background image to the Custom UItoolbar where it has 4 Custom UIBarButton it in.I want to add background image for the ToolBar i searched many things and tried but nothing is working. can anyone please tell me how to add background image for Custome UIToolBar for the Frame which i have specified.
UIToolBar *toolBar =[[UIToolBar alloc]init];
-(void)layoutSubviews{
CGRect frame;
frame = CGRectMake(20 ,90, 150, 30);
toolBar.frame = frame;
UIImage* toolbarImage = [UIImage imageNamed: #"toolbar_background.png"];
[[UIToolbar appearance]
setBackgroundImage: toolbarImage
forToolbarPosition: UIToolbarPositionAny
barMetrics: UIBarMetricsDefault];
}
The Above code is not working For me as mine is Custom Toolbar adding progrmatically and also i am adding it as per requirment.
I had the same problem and now, it is working fine. You can try it, if its works fine,
1.First i set the tool bar hidden to NO.
[self.navigationController setToolbarHidden:NO animated:YES];
2.addin Image to UItoolbar
UIImage *toolbarImage = [[UIImage imageNamed:#"search_BottomBar1.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UIToolbar appearance]setBackgroundImage:toolbarImage forToolbarPosition:UIToolbarPositionBottom barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance]setTintColor:[UIColor grayColor]];
i added the bar Button to it.
UIBarButtonItem *button2 = [[UIBarButtonItem alloc]initWithTitle:#"My Place"
style:UIBarButtonItemStyleBordered target:self action:#selector(clickedButton1)];
NSArray *itemsN = [NSArray arrayWithObjects:button0,button1,button2, nil];
[self setToolbarItems:itemsN animated:NO];
Try this, Hopefully it will works..

How can I add navigationbar background image to MFMailComposeViewController on ios7

I am using MFMailComposeViewController.I can't add navigationBar background image to MFMailComposeViewController on ios7.My Code working ios7 before .But doesn't work on ios7.How can I add navigationbar background image to MFMailComposeViewController on ios7?
MFMailComposeViewController *mailCompose = [[MFMailComposeViewController alloc] init];
mailCompose.mailComposeDelegate = self;
[mailCompose setSubject:#"SubjectName"];
[mailCompose setMessageBody:shareBodyString isHTML:NO];
if ([self respondsToSelector:#selector(presentViewController:animated:completion:)])
{
[self presentViewController:mailCompose animated:YES completion:nil];
}
else {
[self presentModalViewController:mailCompose animated:YES];
}
[mailCompose.topViewController.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"navigationbar-background.png"] forBarMetrics:UIBarMetricsDefault]; // working before ios7
Use the Appearance Proxy. Following code will target the whole application :
UINavigationBar *navBar = [UINavigationBar appearance];
[navBar setBackgroundImage:[UIImage imageNamed:#"navigationbar-background.png"] forBarMetrics:UIBarMetricsDefault];
If you prefer to target only in MFMailComposeViewController change the first line with this :
navBar = [UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil];
If you already customised navigation bar and also want it to apply MFMailComposeViewController, It only allows to do it with UIAppearance proxy. For iOS 7.1.1, i replaced navigation bar background but couldn't change status bar background. Also it greyed out bar button items on subsequent calls. Therefore I stop customising and tried to turn back to default navigation bar style before creating MFMailComposeViewController
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
[[UINavigationBar appearance] setBarStyle:UIBarStyleDefault];
[[UINavigationBar appearance] setTintColor:nil];
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],NSForegroundColorAttributeName,[UIFont fontWithName:#"Helvetica-Bold" size:18.0], NSFontAttributeName, nil]];
MFMailComposeViewController *mailComposer =[[MFMailComposeViewController alloc] init];

How do I remove the gradient from UIToolbar in iPad?

I am using UIToolbar in iPad App,How can I remove the gradient background from it? Below is my Code.
aToolbar.barStyle = UIBarStyleBlackTranslucent;
aToolbar.tintColor = [UIColor blackColor]; toolbar.alpha = 1.0;
You need to set image in UIToolbar so remove Gradient.
My suggestion is please set image and create custom UItoolbar.
For that code is below.
UIImage *gradientImage44 = [[UIImage imageNamed:#"imageName.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
// Set the background image for *all* UINavigationBars
[[UIToolbar appearance] setBackgroundImage:gradientImage44
forBarMetrics:UIBarMetricsDefault];

Resources