【问题标题】:UIBarButtonType as a UIButton. Not on a NavigationBar!UIBarButton 类型为 UIButton。不在导航栏上!
【发布时间】:2011-02-24 15:52:54
【问题描述】:

我想使用样式更好的 UIBarButtonType 作为典型的 UIButton。这只是用于视图而不是导航栏。

我真的不想在图像应用程序中重新创建按钮并应用于各种状态。我知道如何反其道而行之,所以一定有办法。

请帮忙。

【问题讨论】:

    标签: xcode ipad ios uibutton uibarbuttonitem


    【解决方案1】:

    我试过了,效果很好:

    UIButton *info = [UIButton buttonWithType:UIButtonTypeInfoLight];
    UIBarButtonItem *infoBis = [[UIBarButtonItem alloc] initWithCustomView:info];
    NSArray *array = [[NSArray alloc] initWithObjects:infoBis, nil];
    [tool setItems:array animated:YES]; //tool = UIToolbar
    

    别忘了在你的 UIBarButtonItem 上放一个目标;)

    【讨论】:

      【解决方案2】:

      你不能那样做。 UIBarButtonItems 仅用于 UIToolbar 和 UINavigationBar。 您需要创建自己的背景图像。这不是什么大问题,就几行。

      【讨论】:

      • MacTeo,谢谢伙计。我最终创建了 UIToolBar 的子类并绘制透明像素:code- (void)drawRect:(CGRect)rect { UIImage *image = [UIImage imageNamed:@"transparent.png"]; [图像绘制矩形:矩形]; [图片发布]; code 然后将我想要的 UIBarButtonItem 添加到该子类工具栏的实例中。然后把它放在我需要的地方。工作得很好。但我最终在 UI 设计上走了一条不同的路线,所以没有人会看到那个实现。
      猜你喜欢
      • 2017-07-29
      • 1970-01-01
      • 1970-01-01
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多