Iphone 更改MFMailComposeViewController的标题
我正在应用程序中使用MFMailComposeViewController处理应用内电子邮件,但无法更改标题。默认情况下,它在标题中显示主题,但我想将标题设置为其他内容。我该怎么做 我试过:Iphone 更改MFMailComposeViewController的标题,iphone,objective-c,email,iphone-sdk-3.0,mfmailcomposeviewcontroller,Iphone,Objective C,Email,Iphone Sdk 3.0,Mfmailcomposeviewcontroller,我正在应用程序中使用MFMailComposeViewController处理应用内电子邮件,但无法更改标题。默认情况下,它在标题中显示主题,但我想将标题设置为其他内容。我该怎么做 我试过: controller.title = @"Feedback"; 但它不起作用 这是我的密码: - (IBAction)email { NSArray *array = [[NSArray alloc] initWithObjects:@"myemail@gmail.com", nil];
controller.title = @"Feedback";
但它不起作用
这是我的密码:
- (IBAction)email {
NSArray *array = [[NSArray alloc] initWithObjects:@"myemail@gmail.com", nil];
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
[[controller navigationBar] setTintColor:[UIColor colorWithRed:0.36 green:0.09 blue:0.39 alpha:1.00]];
controller.mailComposeDelegate = self;
controller.title = @"Feedback";
[controller setSubject:@"Long subject"];
[controller setMessageBody:@""
isHTML:NO];
[controller setToRecipients:array];
[self presentModalViewController:controller animated:YES];
[controller release];
[array release];
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[self becomeFirstResponder];
[self dismissModalViewControllerAnimated:YES];
}
从MFMailComposeViewController类引用: 重要提示:邮件合成界面本身是不可自定义的,不能由应用程序修改。此外,在显示界面后,不允许您的应用程序对电子邮件内容进行进一步更改
最有可能的情况是,您必须在视图层次结构中深入查找包含标题的原始UINavigationBar,然后手动设置该标题
在这里,程序类转储可以方便地确定使用的确切类。试用、出错和调试器很可能是您的最佳选择。您可以用一行代码为MFMailComposeViewController设置不同的标题,如下所示
...
[self presentModalViewController:controller animated:YES]; // Existing line
[[[[controller viewControllers] lastObject] navigationItem] setTitle:@"SomethingElse"];
...
但是,此实现有效地依赖于MFMailComposeViewController的未记录特性。您正在访问私有类的navigationItem(MFMailComposeRootViewController),并将其标题更改为邮件主题以外的内容。我赞同Art Gillespie的观点,即你不应该这样做,并且很可能因为这样做而被苹果评论家拒绝。此外,在iPhone操作系统的任何小版本中,此过程都可能完全改变,可能会导致用户崩溃,直到您可以发布更新来修复此行为
不过,决定权在你,如果你仍然想采取这些未经推荐的步骤,那就是你如何做到的。你应该能够只拍摄一个视图(controller.view)并将其放在你的控制器内。。。在那一刻,你没有修改任何东西,你实际上在写电子邮件时,在他们的iPad电子邮件应用程序中做了几乎和苹果一样的事情。。。同样的事情也应该适用于iPhone…Sbrocket的答案非常有效。这是如何添加标题视图(标签):
与上面的评论相同,不建议定制
MFMailComposeViewController
。消息的主题似乎是iOS 8中MFMailComposeViewController的标题。我知道,但我的问题是不允许的,我的问题是;可能吗?怎么做?;-)这仍然是对您问题的相关回答,因为在iPhone上使用私有API是非常不鼓励的。即使有可能,也值得知道这不是建议的行动方针。好吧,也许你是对的,但我仍然想知道如何做到:)?谢谢,我只是想知道如何做到这一点。在和更多的人交谈之后,我决定将我的电子邮件主题改为适合我的主题。无论如何,谢谢:)可以写成controller.topViewController.navigationItem.title=@“SomethingElse”代码>此解决方案在iOS8上对我无效-标题保持不变
// existing
[self presentModalViewController:controller animated:YES];
// new code
CGRect frame = CGRectMake(0, 0, 320, 44);
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont fontWithName:@"MarkerFelt-Thin" size:18.0];
label.adjustsFontSizeToFitWidth = YES;
label.minimumFontSize = 12.0;
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor darkGrayColor];
label.text = @"Your Comments";
[[[[controller viewControllers] lastObject] navigationItem] setTitleView:label];