[英]iPhone/Objective-C - Change default “navigationItem.prompt” color
有沒有辦法將self.navigationItem.prompt
顏色設置為白色? 目前是黑色。
這就是我現在設置導航欄顏色的方式:
// Set top navigation bar.
UINavigationBar *bar = [navController navigationBar];
[bar setTintColor:[UIColor colorWithRed:180.0/255.0 green:25.0/255.0 blue:34.0/255.0 alpha:1]];
UIImageView *navBar = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[navBar release];
..這就是我設置我的navigationItem.prompt
的方式:
self.navigationItem.prompt = @"Tap image for more options.";
現在可以在 iOS 5 或更高版本中使用。 試試這個代碼。
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor, nil]];
恐怕提示顏色是硬編碼的,不能自定義。
我設法使用以下(棘手的)技巧來自定義提示,以替換提示:
navigationItem.prompt = @""
強制navigationBar顯示空提示navigationItem.titleView
設置為:
UILabel
或任何你想替換標題的東西,里面,作為一個子視圖,來替換提示:
.clipsToBounds = NO
以便正確繪制自定義提示我通過覆蓋UIViewController.setTitle:
將其應用於我的所有控制器(這不會按原樣工作/構建,它是一個更復雜代碼的快速提取,但它顯示了邏輯) :
- (void)setTitle:(NSString *)title {
[super setTitle:title];
UILabel *titleLabel = ... build the titleLabel
titleLabel.text = title;
if (self.navigationItem.prompt) {
UILabel *promptLabel = ... build the promptLabel
promptLabel.text = self.navigationItem.prompt;
self.navigationItem.prompt = @"";
promptLabel.centerX = titleLabel.width/2;
promptLabel.top = -31;
[titleLabel addSubview:promptLabel];
titleLabel.clipsToBounds = NO;
}
self.navigationItem.titleView = titleLabel;
}
在 iOs 5 中,我更改了 UINavigationBar 的外觀。 您可以使用以下代碼更改提示顏色
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor grayColor], UITextAttributeTextColor, [UIColor colorWithRed:10 green:20 blue:30 alpha:1.0f], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset, nil]];
我習慣隨機數& colors,您可以通過自己的選擇自定義colors。 希望它會有所幫助。
試試這個方法。
navigationhBar.tintColor = [UIColor colorWithRed:0.4039216041564941 green:0.6470588445663452 blue:0.062745101749897 alpha:1];
Swift:
self.navigationController?.navigationBar.titleTextAttributes =
[NSForegroundColorAttributeName : UIColor.white]
self.navigationController?.navigationBar.barTintColor = UIColor.red
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.