MFMailComposeViewController 中的自定义 UINavigationBar 背景

发布于 2024-12-04 01:55:45 字数 409 浏览 0 评论 0原文

我需要在 MFMailComposeViewController 中为 UINavigationBar 使用自定义背景。以前,我在 UINavigationBar 上使用一个类别来在我的应用程序中实现此目的,但 Apple 特别要求您不要这样做。此外,这可能会或可能不会在当前处于保密协议下的 iOS 未来版本中起作用。

我现在使用 UINavigationBar 的子类来实现我在应用程序其余部分中所追求的外观,但我看不到任何将其与 MFMailComposeViewController 一起使用的方法>。有什么想法吗?

注意:我知道在未来版本的 iOS 中执行此操作的方法,但这需要针对 SDK 的当前版本 (4.3) 进行构建。

I have a need to use a custom background for the UINavigationBar in a MFMailComposeViewController. Previously I was using a category on UINavigationBar to achieve this throughout my app, but Apple specifically requests that you do not do this. Additionally this may or may not work in future versions of iOS that are currently under NDA.

I am now using a subclass of UINavigationBar to achieve the look I'm after in the rest of the app, but I can't see any way to use this with the MFMailComposeViewController. Any ideas?

Note: I'm aware of methods to do this in a future version of iOS, but this needs to be built against a current version (4.3) of the SDK.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

很快妥协 2024-12-11 01:55:45

我刚刚遇到过这个问题——您可以使用 object_setClass 动态注入视图控制器使用的类。

#import <objc/runtime.h>

object_setClass(mailController.navigationBar, [YourNavigationBarSubClass class]);

I just ran across this -- you can dynamically inject the class a view controller uses using object_setClass.

#import <objc/runtime.h>

object_setClass(mailController.navigationBar, [YourNavigationBarSubClass class]);
海之角 2024-12-11 01:55:45

您可以使用下面的代码使用自定义视图来自定义导航栏的 titleView。扩展这个想法,您也许能够调整 titleView 的大小以覆盖整个导航栏,并在其中使用自定义背景来模拟自定义导航栏背景。

我能想到的唯一可能的棘手部分是您需要确保 titleView 位于工具栏中的按钮后面。

获得 MFMailComposerViewController 参考后,以下是自定义 titleView 的代码:

[self presentModalViewController:controller animated:YES];

UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(//set size to navbar size)];
[backgroundView setBackgroundColor:[UIColor colorWithPatternImage://your custom image ]];

controller.topViewController.navigationItem.titleView = backgroundView ;
[controller release];

You can customize the nav bar's titleView with a custom view using the code below. Expanding upon this idea, you may be able to resize the titleView to cover the entire navigation bar and use a custom background in that to simulate a custom navbar background.

The only possible sticky part I can think of is that you need to make sure the titleView sits behind the buttons in the toolbar.

Once you have your MFMailComposerViewController reference, here is the code to customize the titleView:

[self presentModalViewController:controller animated:YES];

UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(//set size to navbar size)];
[backgroundView setBackgroundColor:[UIColor colorWithPatternImage://your custom image ]];

controller.topViewController.navigationItem.titleView = backgroundView ;
[controller release];
┾廆蒐ゝ 2024-12-11 01:55:45

邮件撰写界面本身不可自定义,并且不得由您的应用程序修改。

检查苹果参考以获取更多信息...

http ://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html

但我们可以自定义邮件上述答案给出的组成......

The mail composition interface itself is not customizable and must not be modified by your application.

check apple reference for more info...

http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html

but we can customizable the mail composition as given oin the above answer....

一场信仰旅途 2024-12-11 01:55:45

经过一些黑客和测试,仍然无法自定义按钮。但这是我可以通过设置邮件控制器的色调颜色得到的最接近的结果。

尝试通过 mailController.navigationBar.items 访问它们,它是一个栏项目数组。

MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
mailController.navigationBar.tintColor = [UIColor brownColor];  

After some hacking and testing, still not manage to customize the button. But this is the closest I can get, by setting the tint color of mail controller.

Try accessing them through mailController.navigationBar.items, which is an array of the bar items.

MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
mailController.navigationBar.tintColor = [UIColor brownColor];  
温折酒 2024-12-11 01:55:45

虽然更好地控制外观会很好,但我不认为有一个干净的方法。当你无法更改它时...隐藏它:

NSDictionary *attributes = @{NSForegroundColorAttributeName: [UIColor clearColor]};
[[UINavigationBar appearance] setTitleTextAttributes:attributes];

Although it would be nice to get more control over the appearance, I don't think there is a clean method. When you cant change it...hide it:

NSDictionary *attributes = @{NSForegroundColorAttributeName: [UIColor clearColor]};
[[UINavigationBar appearance] setTitleTextAttributes:attributes];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文