浅色模式 | 深色模式 | 运行时更改 |
---|---|---|
![]() |
![]() |
![]() |
示例
要运行示例项目,请先克隆仓库,然后在示例目录下运行 pod install
要求
- iOS 10+
安装
ContextMenu 可通过 CocoaPods 获得。要安装它,只需在 Podfile 中添加以下行
pod 'SwiftyContextMenu'
用法
let favoriteAction = ContextMenuAction(title: "Looooooooooooong title",
image: UIImage(named: "heart.fill"),
action: { _ in print("favorite") })
let shareAction = ContextMenuAction(title: "Share",
image: UIImage(named: "square.and.arrow.up.fill"),
action: { _ in print("square") })
let deleteAction = ContextMenuAction(title: "Delete",
image: UIImage(named: "trash.fill"),
tintColor: UIColor.red,
action: { _ in print("delete") })
let actions = [favoriteAction, shareAction, deleteAction]
let contextMenu = ContextMenu(title: "Actions", actions: actions)
button.addContextMenu(contextMenu, for: .tap(numberOfTaps: 1), .longPress(duration: 0.3))
深色模式
默认情况下,ContextMenu
会自动根据系统样式(> iOS 13)进行适配,但您可以强制设置外观。
let favoriteAction = ContextMenuAction(
title: "Like",
image: UIImage(named: "heart.fill"),
tintColor: UIColor.black,
tintColorDark: UIColor.white,
action: { _ in }
)
let contextMenu = ContextMenu(
mode: .light, //.automatic, .light or .dark
title: "Actions",
actions: actions
)
如果您将模式设置为 .automatic
,请确保为包含亮色和暗色外观的 ContextMenuAction
提供一个 tintColor
。 (当设置为 .automatic
时,仅应用 tintColor
。)
作者
Mario Iannotta, [email protected]。
如果您喜欢这个 git,可以在这里或 Twitter 上关注我 @MarioIannotta;有时我会发布有趣的内容。
许可证
ContextMenu 依据 MIT 许可证提供。更多详情请参阅 LICENSE 文件。
待办事项
- 记录所有公共内容
- 支持暗黑模式
- 改进 README 使用部分
- 支持动态类型