gpt4 book ai didi

ios - 自定义从 UITextView 打开的自动 MFMailComposeViewController

转载 作者:可可西里 更新时间:2023-11-01 03:57:01 25 4
gpt4 key购买 nike

我有一个简单的 UITextView,里面有一个电子邮件链接。 TextView 是可选择的并检测链接。这样,您可以单击电子邮件,它会以模式方式打开一个 MFMailComposeViewController View Controller 。

但是,我在应用启动时做了一些定制:

[[UINavigationBar appearance] setBarTintColor: myGreyColor];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: myFont}];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

这样,所有导航栏都是灰色的,带有白色文本和白色按钮,标题具有自定义字体。

我的问题是所有这些都不适用于邮件编辑器:栏是灰色的,标题是白色的,但字体是默认的 helvetica neue,按钮是默认的蓝色。而且,状态栏是黑色的,即使我的 Info.plist 说 UIStatusBarStyleLightContentView controller-based status bar appearance 设置为 NO

我知道手动调用时如何自定义MFMailComposeViewController,但是这里自动弹出。如何将我的样式应用于它?

最佳答案

编辑

自定义 MFMailComposeViewController 的外观是一个非常糟糕的主意,很可能会使您的应用程序被 Apple 拒绝。仅当您不打算将您的应用程序提交给 Apple 时才应使用以下解决方案。


看起来我解决了,感谢Ray Wenderlich (再次..)。这是完整的代码:

- (void)viewDidLoad
{
[super viewDidLoad];

[…] // Initializations

// Link detection
[_textView.attributedText addAttribute:NSLinkAttributeName value:@"mail://contact" range:[[content string] rangeOfString:@"contact@mymail.com"]];

_textView.delegate = self;

}

// Handle the link tap yourself
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {

if ([[URL scheme] isEqualToString:@"mail"]) {

MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init];
[mailVC setToRecipients:@[@"contact@ mymail.com"]];
[mailVC setSubject:@"About QuickReminder for iOS"];
mailVC.mailComposeDelegate = self;

// Re-set the styling
[mailVC.navigationBar setBarTintColor:myGreyColor];
[mailVC.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: myFont}];
[mailVC.navigationBar setTintColor:[UIColor whiteColor]];

[self presentViewController:mailVC animated:YES completion:^{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}];

return NO;
}
return YES;
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Result: canceled");
break;
case MFMailComposeResultSaved:
NSLog(@"Result: saved");
break;
case MFMailComposeResultSent:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result" message:@"Mail Sent Successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
break;
case MFMailComposeResultFailed:
NSLog(@"Result: failed");
break;
default:
NSLog(@"Result: not sent");
break;
}

[controller dismissViewControllerAnimated:YES completion:nil];
}

关于ios - 自定义从 UITextView 打开的自动 MFMailComposeViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22144874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com