Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 向工具栏添加按钮_Iphone_Objective C_Ios_Xcode - Fatal编程技术网

Iphone 向工具栏添加按钮

Iphone 向工具栏添加按钮,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,我需要添加一个透明的工具栏,并添加4个按钮上的图像。我如何通过代码实现这一点 到目前为止我的工作 我添加了工具栏并使其透明 现在我尝试添加4个带有图像的按钮。我该怎么做?(这4个按钮还应该有一个操作方法,因此当有人点击它时,操作应该启动) 只需为4个按钮编写上述代码 更新1: 使用以下代码在按钮中获取图像 UIImageView *btn1Img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Btn1Img"]]; UIB

我需要添加一个透明的工具栏,并添加4个按钮上的图像。我如何通过代码实现这一点

到目前为止我的工作

我添加了工具栏并使其透明 现在我尝试添加4个带有图像的按钮。我该怎么做?(这4个按钮还应该有一个
操作
方法,因此当有人点击它时,操作应该启动)

只需为4个按钮编写上述代码

更新1:

使用以下代码在按钮中获取图像

UIImageView *btn1Img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Btn1Img"]];

UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithCustomView:btn1Img];

注意,对于以上内容,您需要使用导航视图控制器上的工具栏。

好,但按钮中的图像在哪里?我也需要添加图像。我不想要标题,我只想显示图片OK,但是按钮上的图片在哪里?我也需要添加图像。我不想要标题,我只想显示图片。我做了投票,但@ade首先修改了代码:S无论如何,谢谢你:*别担心,我很快会发布更多问题。确保你先回答:D
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"Item" style:UIBarButtonItemStyleBordered target:self action:@selector(action];

UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"Item1" style:UIBarButtonItemStyleBordered target:self action:@selector(action];

NSArray *buttons = [NSArray arrayWithObjects: item1, item2, nil];
[toolBar setItems: buttons animated:NO];

[item1 release];
[item2 release];
UIImageView *btn1Img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Btn1Img"]];

UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithCustomView:btn1Img];
NSMutableArray *buttonsArray = [[NSMutableArray alloc] init];
UIBarButtonItem *myButton1=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"email.png"] style:UIBarButtonItemStylePlain target:self action:@selector(toolbarButtonPressed1:)];
[buttonsArray addObject:myButton1];
UIBarButtonItem *myButton2 = [[UIBarButtonItem alloc] initWithTitle:@"button 2" style:UIBarButtonItemStylePlain target:self action:@selector(toolbarButtonPressed2:)];  
[buttonsArray addObject:myButton2];
[self setToolbarItems:buttonsArray animated:YES];