【发布时间】:2011-02-24 15:52:54
【问题描述】:
我想使用样式更好的 UIBarButtonType 作为典型的 UIButton。这只是用于视图而不是导航栏。
我真的不想在图像应用程序中重新创建按钮并应用于各种状态。我知道如何反其道而行之,所以一定有办法。
请帮忙。
【问题讨论】:
标签: xcode ipad ios uibutton uibarbuttonitem
我想使用样式更好的 UIBarButtonType 作为典型的 UIButton。这只是用于视图而不是导航栏。
我真的不想在图像应用程序中重新创建按钮并应用于各种状态。我知道如何反其道而行之,所以一定有办法。
请帮忙。
【问题讨论】:
标签: xcode ipad ios uibutton uibarbuttonitem
我试过了,效果很好:
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 上放一个目标;)
【讨论】:
你不能那样做。 UIBarButtonItems 仅用于 UIToolbar 和 UINavigationBar。 您需要创建自己的背景图像。这不是什么大问题,就几行。
【讨论】:
code- (void)drawRect:(CGRect)rect { UIImage *image = [UIImage imageNamed:@"transparent.png"]; [图像绘制矩形:矩形]; [图片发布]; code 然后将我想要的 UIBarButtonItem 添加到该子类工具栏的实例中。然后把它放在我需要的地方。工作得很好。但我最终在 UI 设计上走了一条不同的路线,所以没有人会看到那个实现。