2012-11-27 69 views
2

我希望你能幫我設置我的導航欄的背景顏色。正如你可以在下面的第一張圖片中看到的那樣,酒吧是淡藍色/灰色,但我希望它像第二張圖片「收藏」。如何在UINavigationBar上設置backgroundColor(tintColor)

enter image description here

我有另外一個的viewController在我的項目(見第二張照片 「Favoritter」),其中它的工作原理。但是我看不到我在這裏做錯了什麼,navigationBar只會採用淺藍/灰色而不是黃色。

enter image description here

我的代碼是這樣的:

------------------ InstantCabAppDelegate.m文件--------- --START -------

//InstantCabAppDelegate.m file 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Create tabBarController instance 
    tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil]; 

    // Create instances of navigation controller and view controllers 
    orderController = [[OrderController2 alloc] initWithNibName:@"Order2" bundle:nil]; 

    UINavigationController* firstnavigationController = [[UINavigationController alloc] initWithRootViewController:orderController]; 

    ICStatusViewController *statusController = [[ICStatusViewController alloc] initWithStatus]; 
    UINavigationController *statusNavController = [[UINavigationController alloc] initWithRootViewController:statusController]; 

    ICSettingsViewController *settingsController = [[ICSettingsViewController alloc] init]; 
    UINavigationController *settingsNavController = [[UINavigationController alloc] initWithRootViewController:settingsController]; 

    UIViewController *company_controller = nil; 
    company_controller = [[ICCompaniesGridController alloc] initWithCompanies:[[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Companies" ofType:@"plist"]]]; 

    tabBarController.viewControllers = [NSArray arrayWithObjects:firstnavigationController, settingsNavController, statusNavController, company_controller, nil]; 

    [window setRootViewController:tabBarController]; 
    [window makeKeyAndVisible]; 
    return YES; 
} 

------------------ ICStatusViewController.m file ----------- START -------

// ICStatusViewController.m file 

#import "ICStatusViewController.h" 
#import "LocalizationSystem.h" 
#import "ICTemporaryStore.h" 
#import "Debug.h" 

@implementation ICStatusViewController 

@synthesize doneCallbackBlock=_doneCallbackBlock, cancelCallbackBlock=_cancelCallbackBlock; 
@synthesize myTableView, no_statuses, no_statuses_label, delegate; 

- (id)initWithStatus 
{ 
    if ((self = [super initWithNibName:@"StatusList" bundle:nil])) 
    { 
     self.title = AMLocalizedString(@"kStatusTitle", @""); 
     self.tabBarItem.image = [UIImage imageNamed:@"status_icon"]; 

     self.no_statuses = AMLocalizedString(@"kStatusListNoStatusList", @""); 
     first_color = TABLE_VIEW_BACKGROUND_COLOR; 
     second_color = first_color; 
     self.doneCallbackBlock = nil; 
     self.cancelCallbackBlock = nil; 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background-nologo"]]; 
    self.view.backgroundColor = [UIColor clearColor]; 
    self.myTableView.backgroundColor = TABLE_VIEW_BACKGROUND_COLOR; 

    if ([statusObjects count] == 0) 
    { 
     self.myTableView.hidden = YES; 

     self.no_statuses_label.text = self.no_statuses; 
     self.no_statuses_label.hidden = NO; 
     no_status_background.hidden = NO; 
    } 

    [self.no_statuses_label setTextColor:[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0]]; 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    if ([statusObjects count] == 0) 
    { 
     self.myTableView.hidden = YES; 
     self.no_statuses_label.text = self.no_statuses; 
     self.no_statuses_label.hidden = NO; 
     no_status_background.hidden = NO; 
     self.navigationItem.rightBarButtonItem = nil; 
    } 
    else 
    { 
     self.myTableView.hidden = NO; 
     self.no_statuses_label.hidden = YES; 
     no_status_background.hidden = YES; 
    } 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    NSInteger retval = 0; 
    for (int i=0; i<[statusObjects count]; i++) 
    { 
     StatusObj *add = [statusObjects getStatusAtIndex:i]; 
     if (add.status_id && [add.status_id length] > 0 && [add.status_type isEqualToString:@"STATUS_ORDER"]) 
     { 
      retval++; 
     } 
    } 
    return retval; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifierStatus = @"StatusCell"; 
    __unsafe_unretained NSString *CellIdentifier = CellIdentifierStatus; 
    StatusCell* cell = (StatusCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[StatusCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
     [[cell textLabel] setTextColor:TABLE_VIEW_TEXT_LABEL_COLOR]; 
     [[cell detailTextLabel] setTextColor:TABLE_VIEW_DETAIL_TEXT_LABEL_COLOR]; 
     [[cell detailTextLabel] setNumberOfLines:3]; 
    }  

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    dateString = [dateFormat stringFromDate:current_order.order.time]; 
    NSString *str = AMLocalizedString(@"kStatusListDetailsToDay", @""); 
    textLabelString = [NSString stringWithFormat:@"%@ - %@", str, dateString]; 

    [cell.textLabel setText:textLabelString]; 

    [cell.detailTextLabel setText:detailTextString]; 

    [cell setBackgroundColor:[UIColor redColor]]; 

    [cell.dateLabel setBackgroundColor:[UIColor clearColor]]; 
    cell.accessoryType = UITableViewCellAccessoryNone; 

    return cell; 
} 

------------- ----- ICStatusViewController.h文件----------- START -------

// ICStatusViewController.h 

#import <UIKit/UIKit.h> 
#import "Status.h" 
#import "StatusCell.h" 
#import "StatusControllerDelegate.h" 
#import "ICStatusDetailsController.h" 

typedef void (^ICStatusViewControllerDoneCallbackBlock)(id userInfo); 
typedef void (^ICStatusViewControllerCancelCallbackBlock)(void); 

@interface ICStatusViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UIActionSheetDelegate, ICStatusDetailsControllerDelegate> { 
    id<Statuses> statusObjects; 
    NSString *no_statuses; 
    NSOperationQueue *queue; 
    NSTimer *statusTimer; 
    __unsafe_unretained id<StatusControllerDelegate> delegate; 

    UIColor *first_color; 
    UIColor *second_color; 

    IBOutlet __unsafe_unretained UITableView *myTableView; 
    IBOutlet __unsafe_unretained UILabel *no_statuses_label; 
    IBOutlet __unsafe_unretained UIImageView *no_status_background; 

@private 
    ICStatusViewControllerDoneCallbackBlock _doneCallbackBlock; 
    ICStatusViewControllerCancelCallbackBlock _cancelCallbackBlock; 
} 

@property (nonatomic, unsafe_unretained) UITableView* myTableView; 
@property (nonatomic, copy) NSString* no_statuses; 
@property (nonatomic, unsafe_unretained) UILabel* no_statuses_label; 
@property (nonatomic, unsafe_unretained) id <StatusControllerDelegate> delegate; 
@property (nonatomic, copy) ICStatusViewControllerDoneCallbackBlock doneCallbackBlock; 
@property (nonatomic, copy) ICStatusViewControllerCancelCallbackBlock cancelCallbackBlock; 

- (id)initWithStatus; 

@end 

回答

0

只需添加這行設置黃色在ICStatusViewControllerviewDidLoad:方法navigationcontroller類..

[self.navigationController.navigationBar setTintColor:[UIColor yellowColor]]; 

,也有像波紋圖像..

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"yourImageName"] forBarMetrics:UIBarMetricsDefault];// write your image name like yellow image 

我希望這會幫助你...

+0

感謝它的工作。我按照你告訴我在「viewDidLoad」[self.navigationController.navigationBar setTintColor:NAVIGATION_BAR_TINT_COLOR]; – user1758654

+1

@ user1758654歡迎光臨隊友,如果這個答案對你有用,那麼接受和upvote答案隊友.. :) –

2

您可以設置導航欄的色調顏色或使用圖像,而不是導航欄和隱藏的導航欄,使用:

navigationController.navigationBarHidden = YES; 
0

什麼是你的tableView的風格?如果tableView的樣式爲,則無法在iOS 6上更改backgroundColor。嘗試更改tableView的backgroundView。

self.settingsTableView = [[UITableView alloc] initWithFrame:rect 
                 style:UITableViewStyleGrouped]; 
UIView *view = [[UIView alloc] initWithFrame:settingsTableView.frame]; 
view.backgroundColor = [UIColor redColor]; 
settingsTableView.backgroundView = view; 
1

你是不是在談論一個UITableView,但對UINavigationBar頂部。我修正了你的問題以反映這一點。基本上有兩種方式來設定其tintColor

更容易的選擇將使用外觀協議(iOS 5及更高版本),因爲這將在整個應用程序更改每一個導航欄:
[[UINavigationBar appearance] setTintColor:[UIColor yellowColor]];

或者您可以對每個UINavigationController的所有UINavigationBar執行此操作。
[navigationController.navigationBar setTintColor:[UIColor yellowColor]];

相關問題