Package for custom tooltips in your application
Flexi Tooltip View support Swift Package Manager.
// swift-tools-version:5.1
import PackageDescription
let package = Package(
name: "YourTestProject",
platforms: [
.iOS(.v12),
],
dependencies: [
.package(name: "FlexiTooltipView", url: "https://github.com/mark-kebo/FlexiTooltipView", from: "1.0.0")
],
targets: [
.target(name: "YourTestProject", dependencies: ["FlexiTooltipView"])
]
)
And then import wherever needed: import FlexiTooltipView
- Using Xcode 11 go to File > Swift Packages > Add Package Dependency
- Paste the project URL: https://github.com/mark-kebo/FlexiTooltipView
- Click on next and select the project target
- Don't forget to set
DEAD_CODE_STRIPPING = NO
in yourBuild Settings
(https://bugs.swift.org/plugins/servlet/mobile#issue/SR-11564)
If you have doubts, please, check the following links:
After successfully retrieved the package and added it to your project, just import FlexiTooltipView
and you can get the full benefits of it.
Setup configuration and show tooltip controller:
import FlexiTooltipView
let tooltipItems: [FlexiTooltipItemProtocol] = [
FlexiTooltipImageItem(image: UIImage(named: "test-image"),
imageSize: CGSize(width: 64, height: 64)),
FlexiTooltipTextItem(text: attributtedTitle(text: "Test", weight: .light),
image: UIImage(named: "test-image")),
FlexiTooltipActionsItem(firstAction: FlexiTooltipActionItem(title: attributtedTitle(text: "cancel", weight: .regular),
backgroundColor: .systemYellow,
completion: { [weak self] in
//Some action
}),
secondAction: nil,
alignment: .trailing)
]
var config = FlexiTooltipConfiguration()
config.arrowHeight = 16
config.isNeedShadow = true
config.isTooltipClosable = true
config.topAction = FlexiTooltipActionItem(title: attributtedTitle(text: "Close", weight: .regular),
backgroundColor: .gray) { [weak self] in
//Some top action
}
config.highlightedViews = [button1, button]
let controller = FlexiTooltipViewController(params: FlexiTooltipParams(tooltipItems: tooltipItems,
pointingView: button,
configuration: config))
controller.present(in: navigationController)
You must to set pointingView
or pointing viewRect
in FlexiTooltipParams
. This is exactly the view to which the tooltip will be attached.
Also if you need highlight some views, you can use highlightedViews
in FlexiTooltipConfiguration
.