我想以编程方式将按钮而不是条形按钮项添加到工具栏中。我选择它是因为按钮有图像 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];