How to use BBBadgeBarButtonItem in swift

让人想犯罪 __ 提交于 2020-01-14 06:03:10

问题


I want badge on a BarButton and I came across BBBadgeBarButtonItem but I am not sure if this will work in swift or not.

  1. is it possible ?
  2. if yes how ?

PS I am very new to iOS and swift

When I try to use it like the readme file says, I am getting an error at import line "Expected Identifier at import declaration"


回答1:


You need what's called an Objective-C bridging header since BBBadgeBarButtonItem is written in Objective-C and your project is Swift.

See http://www.learnswiftonline.com/getting-started/adding-swift-bridging-header/ on how to create the bridging header.

Once you've properly created your bridging header you'll then add the following to it:

#import BBBadgeBarButtonItem.h

You should then be able to do something like (untested):

let customButton = UIButton()
let barButton = BBBadgeBarButtonItem(customUIButton: customButton)
barButton.badgeValue = 1



回答2:


Import it in you bridging header like this:

#import <BBBadgeBarButtonItem/BBBadgeBarButtonItem.h>


来源:https://stackoverflow.com/questions/30562831/how-to-use-bbbadgebarbuttonitem-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!