2014-05-03 31 views
1

我試圖通過在UINavigationItem的titleview的顯示UIToolbar:UIToolbar在UINaviationItem怪異線在頂部

UIBarButtonItem *mapItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"world_icon"] 
                  style:UIBarButtonItemStylePlain 
                  target:self action:@selector(hi)]; 
UIBarButtonItem *mapItem2 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"world_icon"] 
                  style:UIBarButtonItemStylePlain 
                  target:self action:@selector(hi)]; 
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 

toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
[toolbar setItems:@[mapItem, spaceItem, mapItem2, spaceItem]]; 
toolbar.backgroundColor = [UIColor clearColor]; 
toolbar.barStyle = UIBarStyleDefault; 
[toolbar setBackgroundImage:[UIImage new] 
       forToolbarPosition:UIBarPositionAny 
         barMetrics:UIBarMetricsDefault]; 
toolbar.tintColor = [UIColor whiteColor]; 

self.navigationItem.titleView = toolbar; 

但我在工具欄上獲得這個奇怪的黑線:

enter image description here

任何想法是什麼造成這種情況?謝謝!

+0

你關閉了你的模擬器,並重新啓動你的Xcode,仍然面臨同樣的問題? –

+0

添加工具欄的邊框並設置邊框顏色清晰。 –

回答

2

我不知道這樣會發生,但我有同樣的問題,像你和我固定它的使用

toolbar.clipsToBounds = YES 

你也可以用以下
OR

[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] 
            forBarPosition:UIBarPositionAny 
             barMetrics:UIBarMetricsDefault]; 

[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]]; 
嘗試
+1

clipsToBounds修復它,謝謝! – 0xSina