【发布时间】:2010-07-21 13:38:05
【问题描述】:
我正在尝试向 UIBarButtonItem 添加图像,我必须在 UIToolbar 中使用它。
我已经设法读取图像,甚至让它与 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];
您的帮助将不胜感激。
谢谢!
Shumais Ul Haq
【问题讨论】:
标签: iphone uibarbuttonitem uitoolbar