设置UIToolBar背景图片我使用下面的代码。
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];
这显示以下输出
但问题出现在哪里是我设定的紫色背景图片?
如果我更改位置顶部,则输出变为
[tool setBackgroundImage:barImage forToolbarPosition:UIToolbarPositionTop
barMetrics:UIBarMetricsDefault];
这是我在设置背景图片时所期望的。
所以我没有任何明确的想法何时使用UIToolBarPositionTop或UIToolBarPositionBottom?
答案 0 :(得分:0)
在Apple docs中声明:
UIToolbarPositionBottom:表示工具栏位于其顶部 包含视图。
UIToolbarPositionTop:表示工具栏位于其底部 包含视图。
Definitelly这有点奇怪(UIToolbarPosition 顶部意味着在底部 ...),但是,就像那样......
也许更容易将其视为:内容位于UIToolbarPositionTop工具栏的上方(顶部)