为什么带有自定义视图的BarButton项目会因图像而延伸?

时间:2018-01-25 10:01:28

标签: ios objective-c uibarbuttonitem

我使用以下代码在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具有相同的大小,但令人惊讶的输出是:

enter image description here

当我调试并检查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

为什么即使给出固定大小的按钮也会发生这种情况?

0 个答案:

没有答案