我想改變我的iOS7應用程序UINavigationBar的外觀。我做了以下內容:iOS 7 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導航欄,然後按我家,再次呈現它,它是我的新面貌。
任何想法,爲什麼它不能在第一次工作?
嘗試在viewDidAppear中移動代碼 – Ilario
我在那裏嘗試過,沒有去過,我也試過在viewWillAppear。 – LilMoke
對於任何其他可能遇到山姆問題的人,我將此代碼:[[UINavigationBar appearance] setBa ...更改爲:[self.navigationController.navigationBar setBa ...以及setTitleTextAttributes行中的代碼。找到答案在這裏:http://stackoverflow.com/questions/17361500/how-to-set-navigation-bar-image-ins-ios-7 – LilMoke