(這是不可能使用新的iOS 5.0外觀API)。
編輯:
的iOS> = 5.0:
設置標題文本屬性的導航欄:
// Customize the title text for *all* UINavigationBars
NSDictionary *settings = @{
UITextAttributeFont : [UIFont fontWithName:@"YOURFONTNAME" size:20.0],
UITextAttributeTextColor : [UIColor whiteColor],
UITextAttributeTextShadowColor : [UIColor clearColor],
UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero]};
[[UINavigationBar appearance] setTitleTextAttributes:settings];
的iOS 5.0 <
UINavigationItem沒有一個名爲標籤或某物的屬性,只有一個titleView。你只能通過設置自定義標籤,因爲這標題視圖 你可以使用下面的代碼來設置字體:(所建議的here)
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
label.font = [UIFont fontWithName:@"YOURFONTNAME" size:20.0];
label.shadowColor = [UIColor clearColor];
label.textColor =[UIColor whiteColor];
label.text = self.title;
self.navigationItem.titleView = label;
[label release];
@rolandjitsu你只需使用NSFontAttributeName而不是UITextAttributeFont。 – CedricSoubrie 2013-12-19 23:57:55
@CedricSoubrie〜是的,這是真的,只是想告訴作者有關這個,所以我們可以有一個更新的答案:) – Roland 2013-12-20 19:08:10
和UITextAttributeTextColor應該用NSForegroundColorAttributeName – bobmoff 2014-03-04 08:25:07