【问题标题】:UIBarButtonItem custom view not displaying properlyUIBarButtonItem 自定义视图未正确显示
【发布时间】:2013-04-26 23:21:24
【问题描述】:

我正在尝试制作一个音频播放器,并在底部有一个工具栏。我以编程方式添加了一个带有UIImageView 的条形按钮项,因为它是customView 属性,但是当图像显示时它几乎不在屏幕上: 图片是Pause@2x.png,是40x40 像素,这就是我添加按钮的方式

UIBarButtonItem *flex1, *flex2;
UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Pause@2x.png"]];
self.play = [[UIBarButtonItem alloc] initWithCustomView:iv];
[self.play setAction:@selector(pauseButtonClicked:)];
flex1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
flex2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[self.bar setItems:@[flex1, _play, flex2]];

Pause.png Pause@2x.png

【问题讨论】:

  • 在使用initWithCustomView 创建的 UIBarButtonItem 上调用 setAction: 毫无意义。它不是一个按钮;它将触摸处理完全留给自定义视图。 (文档在这一点上非常清楚。)

标签: iphone ios objective-c uibarbuttonitem uitoolbar


【解决方案1】:

我稍后在代码中尝试更改工具栏的高度,删除该行修复它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-24
    • 2023-04-05
    • 1970-01-01
    • 2016-02-29
    • 2020-06-25
    • 2016-08-11
    • 1970-01-01
    相关资源
    最近更新 更多