27

添付のスクリーンショットのようなバッジ アラート ラベルを追加しようとしています。

ここに画像の説明を入力

タイトル、ラベル uitabbar アイテムを検索しようとしましたが、行き詰まっています。

どんな提案でも大歓迎です。

4

1 に答える 1

67

Xcode 7.2.1 スウィフト 2.1.1

次のように、目的の UITabBarItem の BadgeValue を設定するだけです。

tabBarController?.tabBar.items?[4].badgeValue = "1"   // this will add "1" badge to your fifth tab bar item


// or like this to apply it to your first tab
tabBarController?.tabBar.items?.first?.badgeValue = "1st"

// or to apply to your second tab
tabBarController?.tabBar.items?[1].badgeValue = "2nd"

// to apply it to your last tab
tabBarController?.tabBar.items?.last?.badgeValue = "Last"

UITabBarItem からバッジを削除するには、 nil 値を追加するだけです

tabBarController?.tabBar.items?.first?.badgeValue = nil
于 2015-04-18T17:35:59.573 に答える