iPhone-如何在没有UIToolBar的情况下使用UIBarButtonItem样式 [英] iphone - How can I use an UIBarButtonItem style without the UIToolBar

查看:44
本文介绍了iPhone-如何在没有UIToolBar的情况下使用UIBarButtonItem样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在没有UIToolBar下方的视图中显示黑色的UIBarButtonItem吗?

Can I show a black style UIBarButtonItem in my view without the underneath UIToolBar?

UIToolBar总是有一种边框,我想要黑色的系统UIBarButtonItem就像黑色的标准取消按钮一样,但不是UIToolBar

The UIToolBar always has a kind of border thing, I want the system UIBarButtonItem in black just like a black standard cancel button, but not the UIToolBar

我该怎么办?

谢谢

推荐答案

有一个厚脸皮的技巧可以帮助您解决这个问题.

there is a cheeky hack that will help you with this.

您要使用样式设置为 UISegmentedControlStyleBar 且仅包含一项的UISegmentedControl.您还需要 setMomentary 为yes-使其表现得像按钮:

you want to use a UISegmentedControl with style set to UISegmentedControlStyleBar and only one item. You also need to setMomentary to yes - to make it behave like a button:

UISegmentedControl *myCustomButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Hello",nil]];
[myCustomButton setSegmentedControlStyle:UISegmentedControlStyleBar];
[myCustomButton setTintColor:[UIColor blackColor]];
[myCustomButton setMomentary:YES];
[self.view addSubview:myCustomButton];

这将为您提供一个外观类似于UIBarButtonItem的按钮,您可以将其添加到普通视图中,就好像它是一个按钮一样.您还可以添加目标和操作.:)

This will give you a button that looks like a UIBarButtonItem that you can add to your normal view as if it were a button. You can add a target and an action as well. :)

这就是您得到的:类似这样的东西:

This is what you get: something like this:

这篇关于iPhone-如何在没有UIToolBar的情况下使用UIBarButtonItem样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆