- (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;
}
Another piece of code
- (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];
}
I'm trying to change the navigation bar color to black, however no matter what i do here, the color still stays default (Blue). How do you change the color of the bar on top of the view??
Try something like:
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
This should be done on viewWillAppear:
as during init
method self.navigationController
will be obtained as nil
and hence will not produce any effect.
Hope this helps.
If you use a programatic approach (seems like you don't) you could write this code
- (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;
}
It works for me. Hope it helps! ;)
精彩评论