2015-01-03 35 views
0

我在導航控制器中使用了兩個圖像。一個用於rightBarButtonItem,另一個用於titleView。我在代碼中創建了兩個。所以我的問題是,標題視圖不在中心位置,它靠近左側。這是因爲正確的bar按鈕,我敢肯定,我測試了它並發現了一些相關的問題,但仍然無法解決問題。無法將UINavigationBar中的圖像設置爲中心

我試過[[UIBarButtonItem appearance] setTitlePositionAdjustment:UIOffsetMake(0.0f, 0.0f) forBarMetrics:UIBarMetricsDefault];但沒有幫我。我真的很感激任何建議。

- (void)setupLogo { 

    [self setNeedsStatusBarAppearanceUpdate]; 

    CGRect myImage = CGRectMake(0, 0, 41, 41); 
    UIImageView *myLogo = [[UIImageView alloc] initWithFrame:myImage]; 
    [myLogo setImage:[UIImage imageNamed:@"logo.png"]]; 
    myLogo.contentMode = UIViewContentModeScaleAspectFit; 
    self.navigationItem.titleView = myLogo; 
    [[UIBarButtonItem appearance] setTitlePositionAdjustment:UIOffsetMake(0.0f, 0.0f) forBarMetrics:UIBarMetricsDefault]; 

} 

回答

2

titleView居中左右項目之間。它不在導航欄上居中。

一種可能的解決方案是添加一個與您的右欄按鈕項目大小相同的虛擬左欄按鈕項目。這將迫使titleView居中。