MFMailComposeViewController 上缺少取消和发送按钮 iOS
Cancel and send button missing on MFMailComposeViewController iOS
我正在开发一个 iOS 应用程序,用户可以在其中发送电子邮件和发送 sms.I 我正在使用 MFMailComposeViewController 和 MFMessageComposeViewController 发送电子邮件和短信,但有时取消和发送按钮会出现在作曲家上,有时它不会根本没有出现。这个问题是随机的,我已经尝试了很多来弄清楚。任何帮助将不胜感激。
代码
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[mail setSubject:Email_Subject];
[mail setMessageBody:Share_Message isHTML:NO];
[mail setToRecipients:@[@""]];
[self presentViewController:mail animated:YES completion:NULL];
我已经在我的 viewController 头文件中实现了 MFMailComposeViewControllerDelegate。
好的,我终于对此有所了解。我的问题部分源于我在我的应用程序委托中更改导航栏颜色 (Swift):
UINavigationBar.appearance().barTintColor = UIColor.black
UIApplication.shared.statusBarStyle = .lightContent
// To get my hamburger menu white colored
UINavigationBar.appearance().tintColor = UIColor.white
由于这个原因,以及与缩放模式的一些交互(见我上面的评论),有时我会在我的邮件控制器中将 Cancel/Send 按钮设置为白色。像这样:
我将向您展示我的 class (Objective C),它显示了邮件控制器,它现在可以帮助我解决这个问题中的问题。请注意该行:
[UINavigationBar appearance].tintColor = appleBlueTintColor;
真的是这一切的秘诀:
#import <MessageUI/MessageUI.h>
@interface SendEmail : MFMailComposeViewController
// Returns nil if can't send email on this device. Displays an alert before returning in this case.
- (id) initWithParentViewController: (UIViewController *) parent;
// Show the email composer.
- (void) show;
// Message to append to the bottom of support emails. The string doesn't contain HTML.
+ (NSString *) getVersionDetailsFor: (NSString *) appName;
@end
@interface SendEmail ()<MFMailComposeViewControllerDelegate>
@property (nonatomic, weak) UIViewController *myParent;
@property (nonatomic, strong) UIColor *previousBarTintColor;
@property (nonatomic, strong) UIColor *previousTintColor;
@end
#import "SendEmail.h"
#import <sys/utsname.h>
@implementation SendEmail
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
// Using this init method depends on the `show` method being called immediately after-- to reset the nav bar colors back to what they were originally.
- (id) initWithParentViewController: (UIViewController *) theParent {
if (![MFMailComposeViewController canSendMail]) {
NSString *title = @"Sorry, the app isn't allowed to send email.";
NSString *message = @"Have you configured this device to send email?";
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
[theParent presentViewController:alert animated:YES completion:nil];
return nil;
}
// The default app nav bar color is black-- and that looks bad on the mail VC. Need to change and then set back both the barTintColor and the tintColor (in the `show` method).
self.previousBarTintColor = [UINavigationBar appearance].barTintColor;
self.previousTintColor = [UINavigationBar appearance].tintColor;
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
// I got this color from the digital color meter-- this is what it is supposed to be on the Cancel/Send buttons.
UIColor *appleBlueTintColor = [UIColor colorWithRed:31.0/255.0 green:134.0/255.0 blue:254.0/255.0 alpha:1.0];
[UINavigationBar appearance].tintColor = appleBlueTintColor;
self = [super init];
if (self) {
self.mailComposeDelegate = self;
self.myParent = theParent;
}
return self;
}
- (void) show {
[self.myParent presentViewController:self animated:YES completion:^{
[[UINavigationBar appearance] setBarTintColor: self.previousBarTintColor];
[UINavigationBar appearance].tintColor = self.previousTintColor;
}];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self.myParent dismissViewControllerAnimated:YES completion:nil];
}
+ (NSString *) getVersionDetailsFor: (NSString *) appName;
{
NSMutableString *message = [NSMutableString string];
[message appendString:@"\n\n\n--------------\n"];
[message appendFormat:@"iOS version: %@\n", [[UIDevice currentDevice] systemVersion]];
[message appendFormat:@"%@ version: %@ (%@)\n", appName,
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
[[NSBundle mainBundle]objectForInfoDictionaryKey:@"CFBundleVersion"]];
[message appendFormat:@"Hardware: %@\n", [self machineName]];
return message;
}
// See
+ (NSString *) machineName;
{
struct utsname systemInfo;
uname(&systemInfo);
return [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}
@end
我的问题是下面一行。只需注释这行,因为它使 Barbutton 标题颜色清晰。
UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.clear], for: .normal)
//comment this line
我正在开发一个 iOS 应用程序,用户可以在其中发送电子邮件和发送 sms.I 我正在使用 MFMailComposeViewController 和 MFMessageComposeViewController 发送电子邮件和短信,但有时取消和发送按钮会出现在作曲家上,有时它不会根本没有出现。这个问题是随机的,我已经尝试了很多来弄清楚。任何帮助将不胜感激。 代码
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[mail setSubject:Email_Subject];
[mail setMessageBody:Share_Message isHTML:NO];
[mail setToRecipients:@[@""]];
[self presentViewController:mail animated:YES completion:NULL];
我已经在我的 viewController 头文件中实现了 MFMailComposeViewControllerDelegate。
好的,我终于对此有所了解。我的问题部分源于我在我的应用程序委托中更改导航栏颜色 (Swift):
UINavigationBar.appearance().barTintColor = UIColor.black
UIApplication.shared.statusBarStyle = .lightContent
// To get my hamburger menu white colored
UINavigationBar.appearance().tintColor = UIColor.white
由于这个原因,以及与缩放模式的一些交互(见我上面的评论),有时我会在我的邮件控制器中将 Cancel/Send 按钮设置为白色。像这样:
我将向您展示我的 class (Objective C),它显示了邮件控制器,它现在可以帮助我解决这个问题中的问题。请注意该行:
[UINavigationBar appearance].tintColor = appleBlueTintColor;
真的是这一切的秘诀:
#import <MessageUI/MessageUI.h>
@interface SendEmail : MFMailComposeViewController
// Returns nil if can't send email on this device. Displays an alert before returning in this case.
- (id) initWithParentViewController: (UIViewController *) parent;
// Show the email composer.
- (void) show;
// Message to append to the bottom of support emails. The string doesn't contain HTML.
+ (NSString *) getVersionDetailsFor: (NSString *) appName;
@end
@interface SendEmail ()<MFMailComposeViewControllerDelegate>
@property (nonatomic, weak) UIViewController *myParent;
@property (nonatomic, strong) UIColor *previousBarTintColor;
@property (nonatomic, strong) UIColor *previousTintColor;
@end
#import "SendEmail.h"
#import <sys/utsname.h>
@implementation SendEmail
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
// Using this init method depends on the `show` method being called immediately after-- to reset the nav bar colors back to what they were originally.
- (id) initWithParentViewController: (UIViewController *) theParent {
if (![MFMailComposeViewController canSendMail]) {
NSString *title = @"Sorry, the app isn't allowed to send email.";
NSString *message = @"Have you configured this device to send email?";
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
[theParent presentViewController:alert animated:YES completion:nil];
return nil;
}
// The default app nav bar color is black-- and that looks bad on the mail VC. Need to change and then set back both the barTintColor and the tintColor (in the `show` method).
self.previousBarTintColor = [UINavigationBar appearance].barTintColor;
self.previousTintColor = [UINavigationBar appearance].tintColor;
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
// I got this color from the digital color meter-- this is what it is supposed to be on the Cancel/Send buttons.
UIColor *appleBlueTintColor = [UIColor colorWithRed:31.0/255.0 green:134.0/255.0 blue:254.0/255.0 alpha:1.0];
[UINavigationBar appearance].tintColor = appleBlueTintColor;
self = [super init];
if (self) {
self.mailComposeDelegate = self;
self.myParent = theParent;
}
return self;
}
- (void) show {
[self.myParent presentViewController:self animated:YES completion:^{
[[UINavigationBar appearance] setBarTintColor: self.previousBarTintColor];
[UINavigationBar appearance].tintColor = self.previousTintColor;
}];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self.myParent dismissViewControllerAnimated:YES completion:nil];
}
+ (NSString *) getVersionDetailsFor: (NSString *) appName;
{
NSMutableString *message = [NSMutableString string];
[message appendString:@"\n\n\n--------------\n"];
[message appendFormat:@"iOS version: %@\n", [[UIDevice currentDevice] systemVersion]];
[message appendFormat:@"%@ version: %@ (%@)\n", appName,
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
[[NSBundle mainBundle]objectForInfoDictionaryKey:@"CFBundleVersion"]];
[message appendFormat:@"Hardware: %@\n", [self machineName]];
return message;
}
// See
+ (NSString *) machineName;
{
struct utsname systemInfo;
uname(&systemInfo);
return [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}
@end
我的问题是下面一行。只需注释这行,因为它使 Barbutton 标题颜色清晰。
UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.clear], for: .normal)
//comment this line