objective-c - 如何在导航栏按钮项中添加自定义图像?

标签 objective-c xcode ios4 iphone

 UIBarButtonItem *doneitem=[[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed:)]autorelease];
    self.navigationItem.rightBarButtonItem=doneitem;

这是我的应用代码,我需要在这个按钮上添加图片吗?

请帮帮我。

最佳答案

试试这个代码:

UIImage* image3 = [UIImage imageNamed:@"mail-48_24.png"];
CGRect frameimg = CGRectMake(0, 0, image3.size.width, image3.size.height);
UIButton *someButton = [[UIButton alloc] initWithFrame:frameimg];
[someButton setBackgroundImage:image3 forState:UIControlStateNormal];
[someButton addTarget:self action:@selector(sendmail)
     forControlEvents:UIControlEventTouchUpInside];
[someButton setShowsTouchWhenHighlighted:YES];

UIBarButtonItem *mailbutton =[[UIBarButtonItem alloc] initWithCustomView:someButton];
self.navigationItem.rightBarButtonItem=mailbutton;
[someButton release];

关于objective-c - 如何在导航栏按钮项中添加自定义图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5933800/

相关文章:

iOS addChildViewController 与 AdMob [iPhone, Objective-C ]

iphone - 如何更改 UIAlertView 中的按钮颜色

iphone - 如何在 iPhone 中使用 wifi 查找位置

iphone - 为什么在对象不是 nil 的情况下我会得到 exc bad access?

iphone - newViewController 始终带有两个 Nib (iPhone 和 iPad)

ios - 使具有动态高度 subview 的 UIScrollView 自动与自动布局一起工作

iphone - 单元测试时为 "Undefined symbols for architecture i386"

ios - 方法【load】是否需要调用【super load】

iphone - 如何使 cocos2d Sprite 每秒缩放(以获得脉动效果)?

video - 试图理解 CMTime 和 CMTimeMake