2013-06-25 53 views
0

我在項目命名的登錄中有標籤欄按鈕我想爲此任何想法分配自定義圖像它有多可能?如何在ipad中爲UIBarButton項目設置圖像

我正在做下面的方式,但應用程序崩潰。

下面是代碼:

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Login" style:UIBarButtonItemStyleBordered target:self action:@selector(loginPressed)]; 
self.navigationItem.leftBarButtonItem = nil; 
[self.navigationItem.rightBarButtonItem setBackgroundImage:[UIImage imageNamed:@"loginN.png"] f 
+0

拖動我的代碼,因爲它是你想要的地方... – Jitendra

+0

你問題看起來很混亂。你在你的問題中提到了UIBarbutton項目,但是在你提到的UITabbarItem的描述和標籤中。你實際使用的是什麼? – iNeal

+0

@iNeal更正 –

回答

1

試試這樣:

UIImage *image = [UIImage imageNamed:@"facebook.png"]; 
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
btn.bounds = CGRectMake(0, 0, image.size.width, image.size.height); 
[btn setImage:image forState:UIControlStateNormal]; 
[btn addTarget:self action:@selector(loginPressed) forControlEvents:UIControlEventTouchDragInside]; 
UIBarButtonItem *rbBtn = [[UIBarButtonItem alloc] initWithCustomView:btn]; 
self.navigationItem.rightBarButtonItem = rbBtn; 
0

試試這個代碼

UIImage* image = [UIImage imageNamed:@"facebook.png"]; 
    CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height); 
    UIButton *someButton = [[UIButton alloc] initWithFrame:frame]; 
    [someButton setBackgroundImage:image forState:UIControlStateNormal]; 
    [someButton addTarget:self action:@selector(facebookshare) 
     forControlEvents:UIControlEventTouchUpInside]; 
    [someButton setShowsTouchWhenHighlighted:YES]; 

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

這可能對你有幫助...

+0

試過這個不行的 –

+0

什麼錯誤顯示 – Jitendra

+0

沒有它不顯示圖像 –

相關問題