我使用以下代码在BarButtonItem
中设置viewDidLoad
:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"menubutton.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(leftMenuButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 32, 32)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
如果您看到框架是(0,0,32,32)。
所以,我期待leftBarButtonItem
具有相同的大小,但令人惊讶的输出是:
当我调试并检查leftBarButtonItem
大小时,它是
po _homeViewController.navigationItem.leftBarButtonItem
<UIBarButtonItem: 0x7fa229606990> view=<UIButton: 0x7fa229535dc0; frame = (0 0; 128 44); opaque = NO; layer = <CALayer: 0x600000236740>>
我的 menubutton.png尺寸为128 X 128
为什么即使给出固定大小的按钮也会发生这种情况?