2013-04-26 68 views
0

要設置UIToolBar背景圖片我使用下面的代碼。如何設置UIToolBarPosition頂部或底部

UIToolbar *tool=[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100.0)]; 
[tool setTintColor:[UIColor darkGrayColor]]; 
UIBarButtonItem *btn=[[UIBarButtonItem alloc] initWithTitle:@"Load" style:UIBarButtonItemStyleBordered target:nil action:nil]; 
[tool setItems:[NSArray arrayWithObject:btn]]; 
UIImage *barImage=[[UIImage imageNamed:@"BarBg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(27,0,27,0)]; 
[tool setBackgroundImage:barImage forToolbarPosition:UIToolbarPositionBottom 
       barMetrics:UIBarMetricsDefault]; 
[self.view addSubview:tool]; 

這顯示了以下輸出

但問題出現在哪裏紫色背景圖片,我已經建立?

enter image description here

如果我改變位置上方則輸出變爲

[tool setBackgroundImage:barImage forToolbarPosition:UIToolbarPositionTop 
        barMetrics:UIBarMetricsDefault]; 

這是我所期望的,設置背景圖片時。

enter image description here

所以我沒有任何明確的想法時使用UIToolBarPositionTop或UIToolBarPositionBottom?

+0

我在這裏找不到問題 – Jonesopolis 2013-04-26 15:39:20

+0

@Jonesy請立即檢查 – weber67 2013-04-26 15:45:08

回答

0

在Apple docs指出:

UIToolbarPositionBottom:表示工具欄處於其含有 視圖的頂部。

UIToolbarPositionTop:表示工具欄位於其包含視圖的 的底部。

Definitelly這是一個有點奇怪(UIToolbarPosition 底部 ...),但是,這就是事情是這樣的......

也許它更容易把它當做:該內容位於UIToolbarPositionTop的工具欄上方(頂部)

相關問題