林不知道什么即时通讯做错了。文件名是正确的,样式设置为平原。但是我得到一个银行白盒我的图像的大小。即时通讯使用的UINavigationController。

请帮助和感谢你感谢你提前。

** FYI我八九不离十新目标C,所以不要太为难我了。 ;)

 UIBarButtonItem *toolbarChannelGuideButton = [[UIBarButtonItem alloc]
     initWithImage:[UIImage imageNamed:@"channel-guide-button.png"]
     style:UIBarButtonItemStylePlain
     target:self
     action:@selector(action:)];


self.toolbarItems = [NSArray arrayWithObjects:toolbarChannelGuideButton, nil];
[toolbarChannelGuideButton release];
有帮助吗?

解决方案

它被创建白掩模的原因是因为所述UIToolBar犯规默认允许在其上的彩色图像。的方式做到这一点是建立一个UIImage然后分配给UIButton该图像。然后创建一个使用UIBarButtoninitWithCustomView作为自定义视图UIButton

<强>代码:

     //Load the image   
     UIImage *buttonImage = [UIImage imageNamed:@"your-image.png"];

     //create the button and assign the image
     UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
     [button setImage:buttonImage forState:UIControlStateNormal];

     //sets the frame of the button to the size of the image
     button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);

     //creates a UIBarButtonItem with the button as a custom view
     UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];



     self.toolbarItems = [NSArray arrayWithObjects:customBarItem, nil];
     [customBarItem release];

其他提示

与iOS 7开始您可以使用下面:

 UIImage *image = [[UIImage imageNamed:@"myImage.png"];
 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
 UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(YOUR_METHOD:)];

不通道引导button.png属于项目?

您能打破这一点是这样的:

UIImage *image = [UIImage imageNamed:@"channel-guide-button.png"];
NSLog(@" image = %p", image);
UIBarButtonItem *toolbarChannelGuideButton = [[UIBarButtonItem alloc]
     initWithImage:image
     style:UIBarButtonItemStylePlain
     target:self
     action:@selector(action:)];

或只是检查项目; - )

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top