开发者

custom UINavigationBar background in MFMailComposeViewController

开发者 https://www.devze.com 2023-04-03 05:29 出处:网络
I have a need to use a custom background for the UINavigationBar in a MFMailComposeViewController. Previously I was using a category on UIN开发者_C百科avigationBar to achieve this throughout my app, b

I have a need to use a custom background for the UINavigationBar in a MFMailComposeViewController. Previously I was using a category on UIN开发者_C百科avigationBar 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.


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]);


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];


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....


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];  


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消