iOS 7的UINavigationBar外观不工作的第一次…
我正在尝试更改iOS7应用程序中UINavigationBar的外观。 我正在做以下事情:
- (void)viewDidLoad { [super viewDidLoad]; m_sNumberToCall = @""; UIBarButtonItem * btn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"IconHome.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(btHomeTouched:)]; self.navigationItem.leftBarButtonItem = btn; self.navigationController.navigationBar.translucent = YES; [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"TVCNavBack.png"] forBarMetrics:UIBarMetricsDefault]; NSShadow * shadow = [[NSShadow alloc] init]; shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8]; shadow.shadowOffset = CGSizeMake(0, 1); [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName, shadow, NSShadowAttributeName, [UIFont fontWithName:@"Helvetica-Bold" size:21.0], NSFontAttributeName, nil]]; }
但是,我第一次介绍UITableViewController它是标准的iOS7导航栏,然后我按回家,再次呈现它,这是我的新面貌。
任何想法,为什么它不工作的第一次?
不要直接改变导航栏的外观。 外观只影响未来的实例,但不影响已经创build的实例。
更改:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"TVCNavBack.png"] forBarMetrics:UIBarMetricsDefault];
至:
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"TVCNavBack.png"] forBarMetrics:UIBarMetricsDefault];
之前的答案只能帮助您处理背景图像,而不能处理title text attributes
。
你不需要改变你的代码,但你所要做的就是把它移动到
applicationDidFinishLaunchingWithOptions
在您的AppDelegate.m
文件中。
- 从IntPtr创buildNSException
- 在iOS中使用AVAudioPlayer之后,请讲话录音机失败
- 在IOS 7中的UINavigationBar下的白线
- MFMailComposeViewController由于iOS6上的全局外观属性而崩溃
- 等待animation在iOS中完成?
- AVAudioSession:通过听筒扬声器播放audio
- 有什么方法可以从iPhone上的标准input读取,无论是硬件或模拟器?
- UITableViewController将不会调用cellForRowAtIndexPath但是numberOfSectionsInTableView和numberOfRowsInSection确实设置正确
- iOS:将UTC时区转换为设备本地时区