iPhone UIToolbar UIButtonItem 突出显示

发布于 2024-08-13 17:02:08 字数 785 浏览 3 评论 0原文

我对 UIToolbar 进行了子类化,并在其中创建了一组 UIButtonItems,所有这些都按顺序添加,并且具有灵活的空间。我现在想在每次点击时切换 UIButtonItems 之一(就像 iPod 中的随机播放按钮一样,白蓝白蓝。我保留了对 UIButtonItem 的引用) 。

// interface
UIButtonItem *_shuffleButton;      // released in dealloc

// implementation
UIImage *_shuffleButtonImage = [UIImage imageNamed:@"shuffle_icon_200x100.png"];
_shuffleButton = [[UIBarButtonItem alloc] initWithImage:_shuffleButtonImage  style:UIBarButtonItemStylePlain target:self action:@selector(shuffleButtonTapped)];

所以现在在 shuffleButtonTapped 中,我想做一些类似的事情:

_shuffleButton.highlighted = YES;
// or 
_shuffleButton.selected = YES;

但是这些工作

我都没有找到任何东西,我开始认为我错过了一些东西,谁能告诉我 我可能是什么?谢谢。

I have subclassed UIToolbar and within it have created a set of UIButtonItems, all added in order and nicely spaced with flexible spaces. I now want to toggle one of the UIButtonItems each time it is tapped (just like the shuffle button in iPod, white blue white blue. I have maintained a reference to the UIButtonItem.

// interface
UIButtonItem *_shuffleButton;      // released in dealloc

// implementation
UIImage *_shuffleButtonImage = [UIImage imageNamed:@"shuffle_icon_200x100.png"];
_shuffleButton = [[UIBarButtonItem alloc] initWithImage:_shuffleButtonImage  style:UIBarButtonItemStylePlain target:self action:@selector(shuffleButtonTapped)];

So now in shuffleButtonTapped I want to do something like:

_shuffleButton.highlighted = YES;
// or 
_shuffleButton.selected = YES;

but neither of these work.

I have searched high and low and after failing to find anything I am starting to think I am missing something, can anyone tell me what it might be?? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

这是我创建自己的 navigationItem 按钮的方法,该按钮实际上是一个视图,可以像任何其他视图一样进行动画处理。

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom ];
btn.frame = CGRectMake(0, 0, 30, 30.0);
[btn setBackgroundColor:[UIColor colorWithRed: 0.3f green:0.3f blue:0.3f alpha:1.0f]];

[btn setImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
[btn addTarget:viewController action:@selector(rightButtonTouchUpInside) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
viewController.navigationItem.rightBarButtonItem = customItem;
[customItem release];

Here is what I did to create my own navigationItem Button which is in fact a view and can be animated just like any other view.

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom ];
btn.frame = CGRectMake(0, 0, 30, 30.0);
[btn setBackgroundColor:[UIColor colorWithRed: 0.3f green:0.3f blue:0.3f alpha:1.0f]];

[btn setImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
[btn addTarget:viewController action:@selector(rightButtonTouchUpInside) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
viewController.navigationItem.rightBarButtonItem = customItem;
[customItem release];
蓝咒 2024-08-20 17:02:08

如果您只想将简单的图像显示为按钮,请改用 UITabBar。它将自动更改选择 UI。

if you just want to show wome simple images as a buttons, use UITabBar instead. It will make selection UI changes automatically.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文