Displaying notification badge like counter in UINavigationbar

后端 未结 3 1367
慢半拍i
慢半拍i 2021-01-25 07:09

I have a requirement to display number of pending notifications in iPhone navigation bar. The appearance should be like that of notification badge - but these are not APNS notif

3条回答
  •  佛祖请我去吃肉
    2021-01-25 07:42

    You need to create a UIBarButtonItem that contains a custom view using initWithCustomView. The custom view could be a custom UIButton with a number badge as subview. With this custom view you can also control the width of the buttons.

    There is no public API to create a notification badge directly. In case of a tab bar item you could set a badge using the property badgeValue - but not with UIBarButtonItem. Here you need to use this open source control: MKNumberBadgeView.

    Note that the property rightBarButtonItems is available since iOS 5. If you only need one item set the rightBarButtonItem instead.

提交回复
热议问题