问题
I want badge on a BarButton and I came across BBBadgeBarButtonItem but I am not sure if this will work in swift or not.
- is it possible ?
- 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