使用initWithImage:(UIImage *)图像将图像添加到UIBarButtonItem [英] add image to UIBarButtonItem using initWithImage:(UIImage *)image

查看:84
本文介绍了使用initWithImage:(UIImage *)图像将图像添加到UIBarButtonItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将图像设置为UIBarButtonItem,然后在创建UIBarButtonItem时使用InitWithImage将其添加到UIToolbar。

I would like to know how to set an image to a UIBarButtonItem which will then be added to a UIToolbar, by using InitWithImage when creating a UIBarButtonItem.

我是执行以下操作,但它会创建一个空白空白,其中图像应位于UIToolbar上

I am doing the following, but it creates a blank whitespace where the image should be on the UIToolbar

UIImage *image = [UIImage imageNamed:@"6.png"];

UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(pp:)];

谢谢!

推荐答案

这是一个从Facebook徽标创建工具栏按钮的示例。
创建指向图像的指针(已添加到xCode的文件),创建自定义按钮,更改按钮大小以匹配图像,设置按钮图像,从按钮视图创建工具栏按钮。

Here's an example that creates a toolbar button from the Facebook logo. Create a pointer to an image (file already added to xCode), create a custom button, change the size of the button to match the image, set image of button, create toolbar button from button view.

UIImage *faceImage = [UIImage imageNamed:@"facebook.png"];
UIButton *face = [UIButton buttonWithType:UIButtonTypeCustom];
face.bounds = CGRectMake( 0, 0, faceImage.size.width, faceImage.size.height );
[face setImage:faceImage forState:UIControlStateNormal];
UIBarButtonItem *faceBtn = [[UIBarButtonItem alloc] initWithCustomView:face];

这篇关于使用initWithImage:(UIImage *)图像将图像添加到UIBarButtonItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆