使UIBarButtonSystemItems出现在圆形矩形按钮中,而不仅仅是它们自己

时间:2012-08-16 02:57:59

标签: iphone xcode

我是以编程方式在工具栏上包含一个操作按钮和一个撰写按钮,代码如下:

UIBarButtonItem *compose = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:7 target:self action:@selector(userWritesHaiku)];

compose.style=UIBarButtonItemStyleBordered;

UIBarButtonItem *action = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:9 target:self action:@selector(userWritesHaiku)];

action.style=UIBarButtonItemStyleBordered;

(然后将它们放入一个数组并将它们分配给工具栏。)

但是这给了我以下输出:

buttons created programmatically

我想要的是以下内容,我可以使用Interface Builder创建,但我没有使用Interface Builder。

buttons created with Interface Builder

如何以编程方式获取后一张图片?

1 个答案:

答案 0 :(得分:1)

项目的style属性的默认值为UIBarButtonItemStylePlain。您需要将其设置为UIBarButtonItemStyleBordered

我在iOS 5.0模拟器中试过这段代码:

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(self)];
//item.style = UIBarButtonItemStyleBordered;
self.toolbar.items = [self.toolbar.items arrayByAddingObject:item];

我得到了这个结果:

plain UIBarButtonItem

然后我将其更改为此代码:

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(self)];
item.style = UIBarButtonItemStyleBordered;
self.toolbar.items = [self.toolbar.items arrayByAddingObject:item];

我得到了这个结果:

bordered UIBarButtonItem