我正在尝试将图像添加到我必须在 UIToolbar 中使用的 UIBarButtonItem。
我已经设法读取了图像,甚至让它用 UIImageView 显示,但是当我将它添加到 UIBarButtonItem 然后将该项目添加到 UIToolbar 时,工具栏只会取代“空白”空间的大小和形状我正在尝试加载的图像。
这就是我正在尝试的。
UIImage *image = [UIImage imageNamed:@"6.png"];
//This is the UIImageView that I was using to display the image so that i know that it is being read from the path specified.
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0, 50, image.size.width, image.size.height);
[self.view addSubview:imageView];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setImage:image forState:UIControlStateNormal];
//This is the first way that I was trying to accomplish the task but i just get a blank white space
//This is the Second way but with the same blank white result.
UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithCustomView:button2];
NSArray *items = [NSArray arrayWithObjects: systemItem1, nil];
//Adding array of buttons to toolbar
[toolBar setItems:items animated:NO];
//Adding the Toolbar to the view.
[self.view addSubview:toolBar];
您的帮助将不胜感激。
谢谢你!
舒迈斯·乌尔哈克