2012-06-23 102 views

回答

8

我已經普遍改變了字體從應用程序委託方所有視圖控制器的所有導航欄我的應用程序。如果你不介意它改變所有的導航欄標題的字體,把類似下面的applicationDidFinishLaunching:withOptions:

if ([[UINavigationBar class] respondsToSelector:@selector(appearance)]) 
     // set the navigation bar font to "courier-new bold 14" 
     [[UINavigationBar appearance] setTitleTextAttributes: 
     [NSDictionary dictionaryWithObjectsAndKeys:[UIColor lightGrayColor], UITextAttributeTextShadowColor, 
                [NSValue valueWithUIOffset:UIOffsetMake(1, 0)], UITextAttributeTextShadowOffset, 
                [UIFont fontWithName:@"CourierNewPS-BoldMT" size:14.0], UITextAttributeFont, 
                nil]]; 

更新: 如果你想具體到這一個情況下,你也許可以使用appearanceWhenContainedIn :使用Alexander Akers在下面的評論中提出的參數,因爲UIViewController繼承自UIAppearanceContainer。我知道appearanceWhenContainedIn:在其他情況下工作,比如UINavigationBar中包含的UIBarButtonItems,所以它在這種情況下應該類似地工作。

+4

'[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class],nil]'? –

+0

該代碼僅在包含在郵件撰寫視圖控制器中時纔會更改導航欄的外觀。 –

+0

@AlexsanderAkers,更新了您的建議的答案。我有使用appearanceWhenContainedIn的經驗:對於UINavigationBar中的UIBarButtonItem;我沒有用它來處理這種類型的案件,但它確實有效。 –

-1

由於MFMailComposeViewControllerUINavigationController的一個實例,您可以設置其topViewController的titleview的如下:

UIViewController *controller = [mailController topViewController]; 

UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 170.0f, 44.0f)]; 
titleView.backgroundColor = [UIColor clearColor]; 

UILabel *label = [[UILabel alloc] initWithFrame:titleView.bounds]; 
label.textColor = [UIColor whiteColor]; 
label.backgroundColor = [UIColor clearColor]; 
label.text = @"Custom Font"; 
label.font = [UIFont italicSystemFontOfSize:27.0f]; 
label.textAlignment = UITextAlignmentCenter; 

[titleView addSubview:label]; 
[label release]; 

controller.navigationItem.titleView = titleView; 
[titleView release]; 
+0

由於某種原因,這不起作用,我複製粘貼你的代碼,並用我的 – xonegirlz

+0

@xonegirlz替換mailController,你提到過,你試過這個代碼。我記得在改變控制欄的特徵方面遇到了問題,這就是爲什麼我要依賴上述答案中所描述的UIA外觀。你也嘗試過嗎?任何更新? –

3

我的猜測是它不能因爲跨進程限制來完成。我可以更改顏色,大小和字體(如果它是內置的系統字體),但嘗試將其更改爲我的應用中包含的任何字體都會失敗。

相關問題