[英]how i can change the background color of navigationBar
在我的導航欄中,我在左側和右側位置有兩個按鈕,在導航標題處有一個segmentetControll視圖。 我想將導航欄的背景顏色更改為黑色,但其上的項目顏色將是另一種顏色。 我該怎么做? 我嘗試將navigationBar的tintColor設置為黑色。 但我表明segmentedControll的顏色和navigationBar上的按鈕也變為黑色。
提前致謝。
嘗試將對象設置為navigationBar的子視圖。
設置色調顏色
UINavigationController *theNavigationController = [[UINavigationController alloc] initWithRootViewController: aFeedControler];
theNavigationController.navigationBar.tintColor = [UIColor blackColor];
在viewControllers中添加segmentedControl作為子視圖,如下所示:
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:[UIImage imageNamed:@"segment_check.png"],
[UIImage imageNamed:@"segment_search.png"],
[UIImage imageNamed:@"segment_tools.png"], nil]];
CGRect frame = CGRectMake(0,0, 200,40);
segmentedControl.frame = frame;
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
segmentedControl.selectedSegmentIndex = 1;
self.navigationItem.titleView = segmentedControl;
對於按鈕,您應該嘗試創建UIButtons而不是UIBarButtonsItems,並將它們添加為子視圖。 如果您創建UIBarButtonsItems並像這樣添加它們self.navigationItem.rightBarButtonItem = tempButton; 你會得到你看到的效果。
如果你把它們作為子視圖添加,你不應該有你提到的問題..希望它有所幫助。
UINavigationController *_navigationController = [[UINavigationController alloc] initWithRootViewController: _viewController];
either this
_navigationController.navigationBar.tintColor = [UIColor blackColor];
OR
_navigationController.navigationBar.barStyle=UIBarStyleBlack;
Now about right and left buttons:
UIButton *btnLeft=[UIButton buttonWithType:UIButtonTypeCustom];
btnLeft.frame=CGRectMake(0.0, 5.0, 50.0, 30.0);
btnLeft.backgroundColor=[UIColor RedColor];
btnLeft.layer.borderColor=[UIColor whiteColor].CGColor;
btnLeft.titleLabel.textColor=[UIColor blackColor];
btnLeft.titleLabel.font=[UIFont boldSystemFontOfSize:10.0];
_navigationController.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:btnLeft];
similary you can add right bar button
您在導航欄中有名為tintColor的屬性。 您可以將其值設置為任何顏色。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.