本文介绍了如何快速使用 BBBadgeBarButtonItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要 BarButton 上的徽章,我遇到了 BBBadgeBarButtonItem 但我不确定这是否可行迅速与否.

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. 有可能吗?
  2. 如果是,如何?

PS 我对 iOS 和 swift 都很陌生

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"

推荐答案

您需要所谓的 Objective-C 桥接头文件,因为 BBBadgeBarButtonItem 是用 Objective-C 编写的,而您的项目是 Swift.

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

参见 http://www.learnswiftonline.com/getting-start/adding-swift-bridging-header/ 关于如何创建桥接头.

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

这篇关于如何快速使用 BBBadgeBarButtonItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 17:41