我要添加按钮,而不是栏按钮项到工具栏编程。 我选择它是因为按钮具有图像infodark defaut。
所以这是怎么做编程?
我要添加按钮,而不是栏按钮项到工具栏编程。 我选择它是因为按钮具有图像infodark defaut。
所以这是怎么做编程?
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];
要添加此按钮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];