测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2017年12月 |
SwiftSwift 版本 | 4.0 |
SPM支持 SPM | ✗ |
Maintained by zhiquan911.
Swift3编写的截屏分享组件
在AppDelegate类中监听设备的快捷键截图
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//开启监听截图工具
CHScreenShotManager.shared.enable = true
CHScreenShotManager.shared.didTakeScreenshot = {
(image, vc) in
if let image = image {
//分享按钮
let shareBtn = CHControlItem(
title: "分享",
titleColor: UIColor.white,
backgroundColor: UIColorFromRGB(0xE10B17),
cornerRadius: 5,
action: {
(screenShotView) in
//把image转为分享的图片样式
let newImage = screenShotView.screenshotImage.ch_addShareInfo(
appLogo: UIImage(named: "swift")!,
qrCode: "www.chbtc.com",
shareText: "扫描图片右侧二维码\n随时随地掌握大行情")
//展示效果图
let sharevc = ShareViewController()
sharevc.shareImage = newImage
vc?.present(sharevc, animated: true)
})
//取消按钮
let cancelBtn = CHControlItem(
title: "取消",
titleColor: UIColor.white,
backgroundColor: UIColorFromRGB(0x999999),
cornerRadius: 5,
action: {
(screenShotView) in
screenShotView.dismiss()
})
vc?.ch_showScreenShotView(screenshotImage: image,
items: [shareBtn, cancelBtn])
}
}
return true
}
通过运行代码执行截屏
/// 分享回调
var shareAction: ((CHShowScreenShotView) -> Void)!
/// 样式2
func shareStyle2() {
self.shareAction = {
(screenShotView) in
//把image转为分享的图片样式
let newImage = screenShotView.screenshotImage.ch_addShareInfo(
appLogo: UIImage(named: "swift")!,
qrCode: "www.chbtc.com",
shareText: "扫描图片右侧二维码\n随时随地掌握大行情")
//展示效果图
let sharevc = ShareViewController()
sharevc.shareImage = newImage
self.present(sharevc, animated: true)
}
if let image = UIApplication.shared.ch_takeScreenshot() {
//分享按钮
let shareText = CHControlItem(
title: "分享",
titleColor: UIColor.darkGray,
isPress: false)
let weixin = CHControlItem(
title: "",
titleColor: UIColor.clear,
image: UIImage(named: "post_type_bubble_weixin")!,
action: self.shareAction)
let quan = CHControlItem(
title: "",
titleColor: UIColor.clear,
image: UIImage(named: "post_type_bubble_weixinquan")!,
action: self.shareAction)
let qq = CHControlItem(
title: "",
titleColor: UIColor.clear,
image: UIImage(named: "post_type_bubble_qq")!,
action: self.shareAction)
let sina = CHControlItem(
title: "",
titleColor: UIColor.clear,
image: UIImage(named: "post_type_bubble_sina")!,
action: self.shareAction)
self.ch_showScreenShotView(screenshotImage: image,
items: [shareText, weixin, quan, qq, sina])
}
}
更详细的集成方法,请查看源代码中的demo示例
为了让开发者更积极分享技术,开源程序代码,我们发起数字货币捐助计划,仅接受以下货币捐款。
BTC 地址: 1HvgRTi2CmaSHUkfWUCAqkYjF7AiBohzbB
ETH/ETC 地址: 0xc312ed502fb57e0c42f9C7663CB7A3B0A6c4f6D2
在 MIT 许可证. 下发布。