美文网首页
swift集成qmui桥接oc

swift集成qmui桥接oc

作者: 雷霆嘎巴嘎嘎 | 来源:发表于2022-05-11 16:08 被阅读0次

    环境:xcode13+

    1.新建项目

    2.pod集成

    切换到项目目录下
    cd 项目目录
    
    $ pod init
    
    vim Podfile
    
    按i进入编辑模式
    # Uncomment the next line to define a global platform for your project
    # platform :ios, '9.0'
    source 'https://github.com/CocoaPods/Specs.git'
    target 'projectName' do
      # Comment the next line if you don't want to use dynamic frameworks
      use_frameworks!
    
      # Pods for projectName
      pod 'QMUIKit'
    
      target 'projectNameTests' do
        inherit! :search_paths
        # Pods for testing
      end
    
      target 'projectNameTests' do
        # Pods for testing
      end
    
    end
    
    如上增加输入 pod 'QMUIKit',然后保存:wq
    pod install
    
    如果出现报错,需要增加(source 'https://github.com/CocoaPods/Specs.git')如上Podfile所示

    Adding spec repo trunk with CDN https://cdn.cocoapods.org/

    3.增加bridge桥接文件

    1.新建header文件,文件名格式(projectName-briding-header.h),文件内引入qmui库


    image.png
    
    #ifndef oc_header_h
    #define oc_header_h
    
    #import <QMUIKit/QMUIKit.h>
    #endif /* oc_header_h */
    
    

    2.build-setting中搜索brid,输入上面的(projectName/projectName-briding-header.h)


    image.png

    4.编译运行

    import UIKit
    
    class ViewController: UIViewController {
        
        
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view.
            self.title = "雷霆嘎巴"
            self.view.backgroundColor = UIColor(hue: 0.50, saturation: 0.20, brightness: 0.86, alpha: 1.00)
            
            let button = QMUIButton()
            
            button.frame = CGRect.init(x: 10, y: 210, width: 300, height: 50)
            button.backgroundColor = UIColor.red
            button.addTarget(self, action: #selector(buttonClick), for: UIControl.Event.touchUpInside)
            self.view.addSubview(button)
            
        }
        @objc func buttonClick(){
            print("点击了雷霆")
        }
        
    
    
    }
    
    

    相关文章

      网友评论

          本文标题:swift集成qmui桥接oc

          本文链接:https://www.haomeiwen.com/subject/zcndurtx.html