2015-02-24 70 views

回答

1

這是不工作?

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 20.0f, 320.0f, 32.0f)]; 
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)]; 

[[self view] addSubview: tempView]; 
[[self view] addSubview: navBar]; 
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle: @"Controls"]; 
[navBar pushNavigationItem:navItem animated:NO]; 
1

在下面的代碼中,我將一個視圖嵌入到導航欄中,其中我的嵌入式視圖繪製了背景和新按鈕。該代碼還涉及在設備旋轉時中繼視圖。

- (void)viewDidLayoutSubviews { 
    [super viewDidLayoutSubviews]; 

    if (view.superview == nil) { 
     [self.navigationBar addSubview:view]; 
     [self.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault]; 
    } 

    CGRect frame = self.navigationBar.frame; 
    frame.size.height = MY_NAVBAR_HEIGHT; 
    self.navigationBar.frame = frame; 
    view.frame = self.navigationBar.bounds; 
} 
相關問題