2011-06-22 56 views
0

我需要在导航栏的添加,取消和返回按钮上放置图像。我已经完成了添加按钮,但没有得到后退按钮。如何在导航栏的按钮上设置图像?

即使使用此添加按钮图像它显示回蓝色自定义button.how设置为此?

UIBarButtonItem *addButton=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"bar_add_button.png"] 
    style:UIBarButtonSystemItemAdd target:self    
    action:@selector(addNote)]; 
+0

您向我们展示了'addButton'代码。 –

+0

这就是我已经把图像添加button.and试图返回按钮和取消按钮 –

回答

3
// Initialize the UIButton 
UIImage *buttonImage = [UIImage imageNamed:@"buttonImage.png"]; 
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[aButton setImage:buttonImage forState:UIControlStateNormal]; 
aButton.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height); 

// Initialize the UIBarButtonItem 
UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton]; 

// Set the Target and Action for aButton 
[aButton addTarget:self action:@selector(aButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; 

// Then you can add the aBarButtonItem to the UINavigationBar 
... 
self.navigationItem.leftBarButtonItem = aBarButtonItem; 

// Release buttonImage 
[buttonImage release]; 
+0

它给出错误,同时初始化UIBarButtonItem,该接口类型不能静态分配 –

+0

*仍然在bBarButtonItem –

+0

it done.thnx开始。我也在寻找后退按钮。 –

相关问题