pod 'BTBubble'
let bubble = MCBubble()
bubble.show(text: "这是一个提示气泡",
direction: .autoVertical,
from: targetView)
let attributedText = NSMutableAttributedString(string: "富文本提示")
attributedText.addAttributes([.foregroundColor: UIColor.red], range: NSRange(location: 0, length: 2))
let bubble = MCBubble()
bubble.show(attributedText: attributedText,
direction: .down,
from: targetView)
let customView = MyCustomView()
let bubble = MCBubble()
bubble.show(customView: customView,
direction: .left,
from: targetView)
let bubble = MCBubble()
bubble.fillColor = .systemBlue
bubble.cornerRadius = 8
bubble.borderColor = .white
bubble.borderWidth = 1
bubble.shadowColor = .black
bubble.shadowOpacity = 0.3
bubble.font = UIFont.systemFont(ofSize: 14)
bubble.textColor = .white
bubble.textAlignment = .center
bubble.arrowSize = CGSize(width: 12, height: 8)
bubble.arrowRadius = 2
bubble.arrowOffset = .auto(offset: 10)
bubble.animationIn = 0.3
bubble.animationOut = 0.2
bubble.entranceAnimation = .scale
bubble.actionAnimation = .pulse
bubble.shouldDismissOnTap = true
bubble.shouldDismissOnTapOutside = true
bubble.tapHandler = { bubble in
print("气泡被点击")
}
show(text:direction:maxWidth:from:duration:)
- 显示文本气泡show(attributedText:direction:maxWidth:from:duration:)
- 显示富文本气泡show(customView:direction:from:duration:)
- 显示自定义视图气泡
update(text:)
- 更新文本内容update(attributedText:)
- 更新富文本内容update(customView:)
- 更新自定义视图
hide(forced:)
- 隐藏气泡
- 气泡的最大宽度和高度会根据屏幕尺寸自动调整
- 使用自定义视图时,请自行管理视图的布局
更多使用示例请参考项目中的示例代码。