TNInfoBubble 是一个使用 Swift 编写的组件,用于创建像 Prisma 应用程序一样的信息气泡。信息气泡的外观可以更改。它与 Storyboards 和代码一起工作。
要运行示例项目,首先克隆仓库,然后从示例目录运行 pod install
命令。
TNInfoBubble 通过 CocoaPods 提供。要安装它,请简单地将以下行添加到您的 Podfile:
pod "TNInfoBubble"
TNInfoBubbleView
IBOutlet
以在您的代码中引用气泡。show()
方法TNInfoBubbleView
实例默认情况下,该组件使用与 Prisma 应用程序中的信息气泡相同的样式(黑色背景,白色文字颜色和 3 像素圆角半径)。
可以更改这些设置。
TNInfoBubbleConfiguration
结构的实例TNInfoBubbleView
实例的 config
属性var config = TNInfoBubbleConfiguration()
config.autoRemoveFromSuperView = true
self.bubble.config = config
属性 | 说明 |
---|---|
backgroundColor | 视图的背景颜色。默认:黑色 |
cornerRadius | 视图的圆角半径。默认:3px |
labelFont | 信息标签的字体。默认:系统字体 14pt |
labelTextColor | 信息标签的文本颜色。默认:白色 |
labelTextAlignment | 信息标签的文本对齐方式。默认:居中 |
labelLineBreakMode | 信息标签的换行模式。默认:单词 |
labelNumberOfLines | 信息标签可以显示的行数。默认:0 |
autoHide | 自动隐藏信息气泡。默认:是 |
numberOfSecondsToAutoHide | 信息气泡自行隐藏之前等待的秒数。默认:3 |
autoRemoveFromSuperView | 从上级视图层次结构中移除视图。默认:否 |
如果您想在气泡显示或隐藏时收到更新,可以通过实现 TNInfoBubbleViewDelegate
协议来设置自己的对象作为委托。
self.infoBubble.delegate = self
...
// MARK: TNInfoBubbleViewDelegate methods
func didShowInfoBubble( infoBubble:TNInfoBubbleView ) {
print("Did show info bubble")
}
func didHideInfoBubble( infoBubble:TNInfoBubbleView ) {
print("Did hide info bubble")
}
如果您不希望使用委托,您还可以使用 completionHandler
属性并设置自己的回调。
self.infoBubble.completionHandler = {
print("Completed")
}
Frederik Jacques, [email protected]
TNInfoBubble 可在 MIT 许可下使用。有关更多信息,请参阅 LICENSE 文件。