簡體   English   中英

如何更改 MFMessageComposeViewController 的標題?

[英]How does one change the title of MFMessageComposeViewController?

我想更改短信 controller 的默認標題。 我該怎么做...嘗試所有正常的東西都行不通。 任何人都知道如何以正確的方式做到這一點?

MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
    ABMultiValueRef multi = ABRecordCopyValue(currentContact, kABPersonPhoneProperty);

    [controller setBody:[smsTextView text]];
    [controller setRecipients:[NSArray arrayWithObjects:(NSString*)ABMultiValueCopyValueAtIndex(multi, 0), nil]];
    [controller setMessageComposeDelegate:self];
    //Todo: Make the Title Change
    [controller setTitle:@"asd"];  
    [[controller navigationItem] setTitle:@"asd"];

    [self presentModalViewController:controller animated:YES];
}

我無法更改標題,但如果您想隱藏標題,可以使文本顏色透明:

NSDictionary *attributes =  [NSDictionary dictionaryWithObjectsAndKeys:[UIColor clearColor],UITextAttributeTextColor, nil];
self.messageComposeVc.navigationBar.titleTextAttributes = attributes;

來源: 我們可以更改 MFmessagecomposeViewcontroller 導航標題字體嗎

我認為您不能更改 MFMailComposeViewController 實例的標題。 (我自己也經歷過。)不幸的是,主題變成了標題,是 class 本身使這種情況發生。 似乎也沒有辦法打敗它。

遍歷子視圖以查找導航項可能有效,但您不能保證 MFMailComposeViewController 的實現和子視圖層次結構在未來的 iOS 版本中不會改變。 因此,如果您選擇遍歷樹,您的應用程序將面臨崩潰的風險。 即使那樣,您也可能無法影響標題(如果說,該屬性是只讀的)。

是的你可以。 As MFMessageComposeViewController inherit from UINavigationController, it also has the "navigationBar" property, that belong to the "UINavigationBar" class, and the in the "UINavigationBar" class, there is a "topItem" property, whose class is "UINavigationItem". “topItem”是 UINavigationController 中當前顯示的項目。 所以可以對“topItem”做一些自定義操作,比如改變“title”、“leftBarButtonItem”、“rightBarButtonItem”等。 如下代碼:

// set the SMS navigationBar backgroundColor
controller.navigationBar.tintColor = [UIColor redColor];
// set its title
controller.navigationBar.topItem.title = @"your new SMS title" ;
// set the Right Cancel Item's title
controller.navigationBar.topItem.rightBarButtonItem.title = @"your SMS cancel title";

關聯 Apple 文檔參考

UINavigationController

UI導航欄

UINavigationItem

願它有所幫助! 你可以試一試!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM