Code Monkey home page Code Monkey logo

chscreenshot's Introduction

CHScreenShot

Swift3编写的截屏分享组件

test1.jpg test2.jpg test3.jpg

Features

  • 完美支持Swift3.0编译
  • 支持设备快捷键截屏和手动截屏
  • 支持扩展预览窗口的按钮样式和执行事件
  • 集成使用简单,二次开发扩展强大

Requirements

  • iOS 9+
  • Xcode 8+
  • Swift 3.0+
  • iPhone/iPad

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

You can install it with the following command:

$ gem install cocoapods

To integrate Log into your Xcode project using CocoaPods, specify it in your Podfile:

use_frameworks!

pod 'CHScreenShot'

Example

在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

Donations

为了让开发者更积极分享技术,开源程序代码,我们发起数字货币捐助计划,捐款只接收以下货币。

  • BTC Address: 1HvgRTi2CmaSHUkfWUCAqkYjF7AiBohzbB

  • ETH/ETC Address: 0xc312ed502fb57e0c42f9C7663CB7A3B0A6c4f6D2

License

Released under MIT License.

chscreenshot's People

Contributors

zhiquan911 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.