Swift setting Badge Value for UITabBarItem

前端 未结 1 1527
忘了有多久
忘了有多久 2020-12-15 16:45

I\'m attempting to add a badge alert label like the one in the screenshot attached.

\"enter

相关标签:
1条回答
  • 2020-12-15 17:38

    Xcode 7.2.1 Swift 2.1.1

    You just have to set the badgeValue for your desired UITabBarItem as follow:

    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"
    

    To remove a badge from the UITabBarItem just add nil value to it

    tabBarController?.tabBar.items?.first?.badgeValue = nil
    
    0 讨论(0)
提交回复
热议问题