2

我在我的視圖中使用uibarbutton來顯示通知證件號碼。我用下面的代碼來顯示。如何更改UIBarbutton中的徽章背景顏色?

barButtonBadge.badgeValue = @"5"; 

如何更改此證件號碼的背景顏色? 現在它採用默認顏色。

+0

徽章是一個小紅色橢圓形,顯示待處理通知項的數量(徽章出現在應用圖標的右上角)。您無法控制徽章的大小或顏色。 –

+0

https://github.com/mikeMTOL/UIBarButtonItem-Badge –

回答

0

通過你的好問題,我從Lalit Kumar鏈接上獲得瞭解決方案。

Add following two libraries in your project 

    1. UIButton+Badge.h and UIButton+Badge.m 
    2. UIBarButtonItem+Badge.h and UIBarButtonItem+Badge.m 


Also import 

     #import "UIButton+Badge.h" 
     #import "UIBarButtonItem+Badge.h" in required view controller. 


in your required ViewController.m 

     UIImage *image2 = [UIImage imageNamed:@"someImage"]; 
     UIBarButtonItem *navRightButton = [[UIBarButtonItem alloc] initWithImage:image2 
                    style:UIBarButtonItemStylePlain 
                   target:self 
                   action:@selector(buttonPress:)]; 
    self.navigationItem.leftBarButtonItem = navRightButton; 
    self.navigationItem.leftBarButtonItem.badgeValue = @"2"; 
    self.navigationItem.leftBarButtonItem.badgeBGColor = [UIColor orangeColor]; //Whatever you want just change the color