Friday 15 March 2013

ios - Showing a white UINavigationBar for MFMailComposer with custom UINavigationBar themes in the app -



ios - Showing a white UINavigationBar for MFMailComposer with custom UINavigationBar themes in the app -

i have simple app uitableviewcontroller. app uses custom themes applies theme background , uinavigationbar. view, have uinavigationbaritem (created in code) brings email sheet mfmailcomposerviewcontroller.

i'm finding weird behaviour custom themed uinavigationbar , want remove image , have white uinavigationbar black buttons (cancel, send, title).

i have code below:

if ([mfmailcomposeviewcontroller cansendmail]) { mfmailcomposeviewcontroller *mailer = [[mfmailcomposeviewcontroller alloc] init]; mailer.mailcomposedelegate = self; [mailer setsubject:@"pdf"]; [mailer addattachmentdata:data mimetype:@"application/pdf" filename:filename]; nsstring *emailbody = @"please find attached pdf"; [mailer setmessagebody:emailbody ishtml:no]; [self presentviewcontroller:mailer animated:yes completion:^{ [[uiapplication sharedapplication] setstatusbarstyle:uistatusbarstylelightcontent]; mailer.navigationbar.titletextattributes = @{nsforegroundcolorattributename : [uicolor blackcolor]}; [[uinavigationbar appearance] setbackgroundimage:nil forbarmetrics:uibarmetricsdefault]; [[uinavigationbar appearance] setbartintcolor:[uicolor blackcolor]]; [[mailer navigationbar] settintcolor:[uicolor blackcolor]]; }]; }

so removing image there. issue works, doesn't create buttons black should be. also, in instances, there occurrences custom themed uinavigationbar image shows through. want never happen.

i went far creating new class subclass of mfmailcomposer , setting "theme" of uinavigationbar white created bar, still brought images sometimes.

what want ensure uinavigationbar never shows image , has black buttons cancel, title , send.

any thoughts appreciated.

update

with removing setbartintcolor , settintcolor code above, have noticed first time invoke mfmailcomposeviewcontroller, theme there in uinavigationbar, if close view, , re-open it, image removed , uinavigationbar white. how can show white always, without theme? have removed code removes images outside of completion block, didn't create difference.

to fill uinavigationbar color can utilize backgroundimage property blank shadow image:

[[uinavigationbar appearance] setbackgroundimage:[self imagewithcolor:[uicolor whitecolor]] forbarmetrics:uibarmetricsdefault]; [[uinavigationbar appearance] setshadowimage:[[uiimage alloc] init]];

-imagewithcolor additional method creating uiimage selected color:

- (uiimage *)imagewithcolor:(uicolor *)color { cgrect rect = cgrectmake(0.0f, 0.0f, 1.0f, 1.0f); uigraphicsbeginimagecontext(rect.size); cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextsetfillcolorwithcolor(context, [color cgcolor]); cgcontextfillrect(context, rect); uiimage *image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); homecoming image; }

then set black text color , black status bar visible:

[[uiapplication sharedapplication] setstatusbarstyle:uistatusbarstyledefault]; [[uinavigationbar appearance] settitletextattributes:@{nsforegroundcolorattributename : [uicolor blackcolor]}];

and don't forget these properties applied every navigation bar. hope helps! :)

ios objective-c uinavigationbar mfmailcomposeviewcontroll

No comments:

Post a Comment