環(huán)境:xcode13+
1.新建項(xiàng)目
2.pod集成
切換到項(xiàng)目目錄下
cd 項(xiàng)目目錄
$ pod init
vim Podfile
按i進(jìn)入編輯模式
# 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
如果出現(xiàn)報(bào)錯(cuò),需要增加(source 'https://github.com/CocoaPods/Specs.git')如上Podfile所示
Adding spec repo
trunk
with CDNhttps://cdn.cocoapods.org/
3.增加bridge橋接文件
1.新建header文件,文件名格式(projectName-briding-header.h),文件內(nèi)引入qmui庫
#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)
4.編譯運(yùn)行
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("點(diǎn)擊了雷霆")
}
}