栏按钮项添加工具栏程序

问题描述 投票:2回答:2

我要添加按钮,而不是栏按钮项到工具栏编程。我选择它是因为按钮具有图像infodark defaut。

所以这是怎么做编程?

iphone xcode uibutton uitoolbar uitoolbaritem
2个回答
7
投票
UIImage* image = [UIImage imageNamed:defaultImage];
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
UIButton* button = [[UIButton alloc] initWithFrame:frame];
[button setTitle:@"Display" forState:UIControlStateNormal & UIControlStateHighlighted];
[button setImage:image forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:selectedImage] forState:UIControlStateSelected];
[button addTarget:self action:@selector(button_Clicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];

0
投票

要添加此按钮UIToolbar你需要这个代码。首先,你可以在这之后初始化UIToolbar

NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:4];

[buttons addObject: barButtonItem];
[buttons addObject: btnFav];
[buttons addObject: btnGeneralPopOverController];
[buttons addObject: showInfo];   

[mytoolbar setItems:buttons animated:NO];
© www.soinside.com 2019 - 2024. All rights reserved.