iOS - 更改UIBarButtonItem的高度

Myt*_*ral 2 uitoolbar uibarbuttonitem ipad ios

UIToolbar有一个很好的调整大小的选项(self.navigationController.toolbar.frame)我想知道是否有人知道一种方法来改变UIBarButtonItem的高度?

我有一个高度为117像素的自定义工具栏,到目前为止,我还没有找到修改工具栏上按钮的方法.此外,我需要它作为一个工具栏,因为显示的视图被另一个动画视图(剪切场景样式)覆盖,而我在第一个视图中设置资源,工具栏需要在所有它期间保持在顶部.

ry_*_*hue 9

我实际上遇到了这个问题,我唯一能想到的就是利用initWithCustomView并传入一个带有定义帧的UIButton.

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

/*
* Insert button styling
*/

button.frame = CGRectMake(0, 0, width, height);

UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
Run Code Online (Sandbox Code Playgroud)

否则,UIBarButtonItem只有一个可以设置的width属性,但遗憾的是不是height属性.我用initWithCustomView做的另一件好事就是传入一个带有按钮的工具栏和其他东西,比如活动指示器.希望这可以帮助.


Jes*_*her 5

UIButton使用您喜欢的框架、图像、目标和选择器等创建一个,然后使用UIBarButtonIteminitWithCustomView:方法并使用 UIButton 作为自定义视图。