gpt4 book ai didi

ios - 如何在 MFMailcomposer View 中显示默认导航栏而不是 ios 中的自定义导航栏

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:37:48 25 4
gpt4 key购买 nike

我有一个自定义导航栏,其中包含所有 View 通用的图像。此外,我还有一个显示的 MFMailComposer View 。但我没有在此处获得带有发送和取消按钮的默认导航栏。我试图从导航栏中删除图像.But not working.This is what i tried:

-(void)mailShare:(id)sender{
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));

if (mailClass != nil) {
//[self displayMailComposerSheet];
// We must always check whether the current device is configured for sending emails
if ([mailClass canSendMail])
{
[self applyComposerInterfaceApperance];


}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Device not configured to send mail" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
alert = nil;
return;
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Device not configured to send mail" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
alert = nil;
return;
}

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
// [ picker.navigationBar setTintColor:[UIColor greenColor]];

[picker setSubject:@"Try this Pack from FORCE PACKS"];


CGRect rect = CGRectMake(0, 44, 320, 440);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];


UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


// Attach an image to the email
NSData *myData = UIImagePNGRepresentation(img);
[picker addAttachmentData:myData mimeType:@"image/jpeg" fileName:@"rainy"];

// Fill out the email body text
NSString *emailBody = @"I'm on the road to recovery! Check out my latest Exercise Log from FORCE Packs";
[picker setMessageBody:emailBody isHTML:NO];

[self presentViewController:picker animated:YES completion:nil];

myData = nil;



}

最佳答案

我在我的应用程序中遇到了同样的问题。我删除了使用 UIAppearance 协议(protocol)设置导航栏图像的代码。相反,我在每个需要自定义导航栏的 View Controller 中设置 UINavigationBar 的图像。

我已经创建了一个 UIViewController 类别,我在每个 UIViewController 的 -viewDidLoad 中调用了一个方法来自定义导航栏。

在UIViewController+Appearance.h中

-(void)changeAppearance;

在UIViewController+Appearance.m中

-(void)changeAppearance{
[self.navigationController.navigationBar setBackgroundImage:[[UIImage imageNamed:@"Header"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setTitleTextAttributes:@{UITextAttributeFont: [UIFont fontWithName:@"CooperBlack" size:18], UITextAttributeTextColor: [UIColor colorWithRed:57.0f/255.0f green:132.0f/225.0f blue:168.0f/225.0f alpha:1],UITextAttributeTextShadowColor: [UIColor clearColor]}];

[self.navigationController.navigationBar setShadowImage:[[UIImage imageNamed:@"Header-shadow"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)]];

[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]]];
}

首先在 View Controller 的.m文件中导入UIViewController+Appearance.h,然后在 View Controller 的中调用-changeAppearance方法>-viewDidLoad 喜欢:

[self changeAppearance];

同时删除您当前用于自定义导航栏的所有调用,例如:[[UINavigationBar appearance] blahBlahBlah]

希望对您有所帮助。

关于ios - 如何在 MFMailcomposer View 中显示默认导航栏而不是 ios 中的自定义导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20688058/

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