【发布时间】:2015-08-29 20:03:40
【问题描述】:
我无法为我的 UINavigationBar 获取自定义样式,该样式设置在 UIViewController 的子类中。
我以前有过这个工作,但不知道为什么它不能在这里工作。
我的视图控制器中有以下代码:
- (void) loadView {
[super loadView];
CGRect frame = self.view.bounds;
navBar = [[UINavigationBar alloc] initWithFrame:frame];
frame.size = [navBar sizeThatFits:frame.size];
[navBar setFrame:frame];
[navBar setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
// The following styling has no effect:
[navBar setBarTintColor:[UIColor blackColor]];
[navBar setTintColor:[UIColor grayColor]];
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],NSForegroundColorAttributeName, nil];
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
UIBarButtonItem * button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay
target:self
action:@selector(nextView:)];
[[self navigationItem] setRightBarButtonItem:button];
[button release];
[navBar setItems:[NSArray arrayWithObject:self.navigationItem]];
[self.view addSubview:navBar];
}
【问题讨论】:
-
这是 UIViewController 的一个子类,让我们将这个子类 CustomViewController 称为“customviewcontroller”类型的所有视图控制器吗?
-
如果是这种情况,那么我可以向您展示如何以编程方式执行此操作,事实上,我现在有一个方法示例,但它很复杂,我不想要如果这不是你的意思,让你感到困惑
标签: ios objective-c uiviewcontroller uinavigationcontroller uinavigationbar