Изменение цвета UINavigationBar - PullRequest
0 голосов
/ 21 мая 2011
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) 
{       
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
                                                                                          target:self
                                                                                          action:@selector(cancel)];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Send to Twitter"
                                                                              style:UIBarButtonItemStyleDone
                                                                             target:self
                                                                             action:@selector(save)];

}
return self;
}

Еще один фрагмент кода

 - (void)loadView 
    {
[super loadView];

self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.view.backgroundColor = [UIColor whiteColor];

self.textView = [[UITextView alloc] initWithFrame:self.view.bounds];
textView.delegate = self;
textView.font = [UIFont systemFontOfSize:15];
textView.contentInset = UIEdgeInsetsMake(5,5,0,0);
textView.backgroundColor = [UIColor whiteColor];    
textView.autoresizesSubviews = YES;
textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

[self.view addSubview:textView];
}

Я пытаюсь изменить цвет панели навигации на черный, однако независимо от того, что я здесь делаю, цвет по-прежнему остается по умолчанию (синий).Как вы меняете цвет панели в верхней части представления ??

enter image description here

Ответы [ 2 ]

6 голосов
/ 21 мая 2011

Попробуйте что-то вроде:

self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

Это должно быть сделано на viewWillAppear:, так как во время init метод self.navigationController будет получен как nil и, следовательно, не даст никакого эффекта.

Надеюсь, это поможет.

0 голосов
/ 21 мая 2011

Если вы используете программный подход (кажется, что нет), вы можете написать этот код

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

// Override point for customization after application launch.

// window initialization
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

YourViewController *viewController = [[YourViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] \
initWithRootViewController:viewController];
[viewController release];
[[navigationController navigationBar] setTintColor:[UIColor blackColor]];
[window addSubview:navigationController.view];

[self.window makeKeyAndVisible];

return YES;

}

Это работает для меня.Надеюсь, поможет!;)

...