Xcode快捷鍵:
格式化代碼:
control + i (Editor-Structure-Re indent)
移動(dòng)代碼:
alt+command+[ (Editor-Structure-Move Line Up)
alt+command+] (Editor-Structure-Move Line Down)
從當(dāng)前位置刪除到分隔符:
例如: 如下代碼, 我們想把dataArray改為resultArray:
let group = dataArray[section]
通常做法是將鼠標(biāo)放到data后面, 然后按delete多次刪除data, 其實(shí)刪除的這一步可以按住alt+delete; 這樣就會(huì)刪除當(dāng)前鼠標(biāo)指針到前面分隔符之間的字符.
向后刪除:
fn + delete; 只是Mac系統(tǒng)的功能, 也就是說(shuō), 所有的編輯界面都可以用, 不僅限于Xcode
創(chuàng)建橋接文件:
因?yàn)槟壳癚MUI還沒(méi)有Swift版本, 是OC版本, 而我們是Swift項(xiàng)目, 所有需要?jiǎng)?chuàng)建橋接文件, 方法是在項(xiàng)目里面創(chuàng)建一個(gè)OC文件, 會(huì)自動(dòng)彈出提示詢問(wèn)是否添加橋接文件, 選擇是就行了
#import <QMUIKit/QMUIKit.h>
使用:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.systemPink
view.addSubview(showMoreButtonView)
}
@objc func onPrimaryClick(){
print("點(diǎn)擊了按鈕")
}
//懶加載
lazy var showMoreButtonView: QMUIButton = {
let result = QMUIButton(frame: CGRect(x: 50, y: 100, width: 200, height: 45))
result.adjustsButtonWhenHighlighted = true//自動(dòng)調(diào)整高亮效果
result.titleLabel?.font = UIFont.systemFont(ofSize: 15)
result.setTitleColor(.white, for: .normal)
result.backgroundColor = UIColor.blue
result.layer.cornerRadius = 5
result.setTitle("從底部顯示更多彈窗按鈕", for: .normal)
result.addTarget(self, action: #selector(onPrimaryClick), for: .touchUpInside)
return result
}()
}
SnapKit -- 登錄注冊(cè)頁(yè)
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.title = "登錄"
//輸入框
view.addSubview(accountView)
view.addSubview(passwordView)
view.addSubview(primaryButtonView)
view.addSubview(registerButtonView)
accountView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16) //距離父視圖左邊距離
make.right.equalToSuperview().offset(-16)//距離父視圖右邊距離
if #available(iOS 11.0, *) {
//距離安全區(qū)域的距離
make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(16)
} else {
// Fallback on earlier versions
}
make.height.equalTo(50)
}
passwordView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16) //距離父視圖左邊距離
make.right.equalToSuperview().offset(-16)//距離父視圖右邊距離
make.top.equalTo(accountView.snp.bottom).offset(16)
make.height.equalTo(50)
}
primaryButtonView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16) //距離父視圖左邊距離
make.right.equalToSuperview().offset(-16)//距離父視圖右邊距離
make.top.equalTo(passwordView.snp.bottom).offset(16)
make.height.equalTo(50)
}
registerButtonView.snp.makeConstraints { make in
make.centerX.equalToSuperview() //水平居中
make.top.equalTo(primaryButtonView.snp.bottom).offset(16)
}
}
//懶加載
lazy var accountView: QMUITextField = {
let result = QMUITextField()
result.textInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)
result.backgroundColor = .lightGray
result.layer.cornerRadius = 5
result.placeholder = "請(qǐng)輸入用戶名"
return result
}()
lazy var passwordView: QMUITextField = {
let result = QMUITextField()
result.textInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)
result.backgroundColor = .lightGray
result.layer.cornerRadius = 5
result.placeholder = "請(qǐng)輸入密碼"
result.isSecureTextEntry = true
return result
}()
lazy var primaryButtonView: QMUIButton = {
let view = QMUIButton()
view.adjustsButtonWhenHighlighted = true
view.titleLabel?.font = UIFont.systemFont(ofSize: 16)
view.setTitleColor(.white, for: .normal)
view.backgroundColor = .blue
view.layer.cornerRadius = 5
view.setTitle("登錄", for: .normal)
view.addTarget(self, action: #selector(onPrimaryClick), for: .touchUpInside)
return view
}()
lazy var registerButtonView: QMUIButton = {
let view = QMUIButton()
view.adjustsButtonWhenHighlighted = true
view.titleLabel?.font = UIFont.systemFont(ofSize: 16)
view.setTitleColor(.gray, for: .normal)
view.setTitle("去注冊(cè)", for: .normal)
view.sizeToFit() //寬高根據(jù)文字大小自適應(yīng)
view.addTarget(self, action: #selector(onRegisterClick), for: .touchUpInside)
return view
}()
@objc func onPrimaryClick(){
print("登錄")
navigationController?.pushViewController(SettingController(), animated: true)
}
@objc func onRegisterClick(){
print("去注冊(cè)")
}
}
SnapKit -- 設(shè)置頁(yè)
在SettingView.swift中, 封裝組件:
/// 設(shè)置itemVIew
class SettingView: UIView {
//重寫構(gòu)造方法
init(){
super.init(frame: CGRect.zero)
innerInit()//定義公共的init方法
}
//重寫可視化的init方法
required init?(coder: NSCoder) {
super.init(coder: coder)
innerInit()//定義公共的init方法
}
func innerInit() {
backgroundColor = .white
addSubview(iconView)
addSubview(titleView)
addSubview(moreIconView)
}
/// 當(dāng)視圖加入父視圖時(shí) / 當(dāng)視圖從父視圖移除時(shí)調(diào)用
override func didMoveToSuperview() {
super.didMoveToSuperview()
//添加約束
iconView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16)
make.centerY.equalToSuperview()
make.width.equalTo(20)
make.height.equalTo(20)
}
titleView.snp.makeConstraints { make in
make.left.equalTo(iconView.snp.right).offset(16)
make.centerY.equalToSuperview()
//不用設(shè)置寬高, 根據(jù)內(nèi)容自動(dòng)寬高
}
moreIconView.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-16)
make.centerY.equalToSuperview()
make.width.equalTo(20)
make.height.equalTo(20)
}
}
/// 左側(cè)圖標(biāo)
lazy var iconView: UIImageView = {
let result = UIImageView()
result.image = UIImage(named: "Setting")
return result
}()
/// 標(biāo)題
lazy var titleView: UILabel = {
let result = UILabel()
result.text = "設(shè)置"
result.textColor = .black
return result
}()
/// 右側(cè)圖標(biāo)
lazy var moreIconView: UIImageView = {
let result = UIImageView()
result.image = UIImage(named: "Arrow")
return result
}()
}
在SettingController.swift中, 使用組件:
class SettingController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.title = "設(shè)置"
self.view.backgroundColor = .systemGray
//-------設(shè)置item
self.view.addSubview(settingView)
self.view.addSubview(collectionView)
//-----設(shè)置約束
settingView.snp.makeConstraints { make in
make.left.equalToSuperview()
make.right.equalToSuperview()
if #available(iOS 11.0, *) {
make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(16)
} else {
// Fallback on earlier versions
}
make.height.equalTo(55)
}
collectionView.snp.makeConstraints { make in
make.left.equalToSuperview()
make.right.equalToSuperview()
make.top.equalTo(self.settingView.snp.bottom).offset(0.5)
make.height.equalTo(55)
}
}
/// 設(shè)置Item
lazy var settingView: SettingView = {
let result = SettingView()
result.titleView.text = "設(shè)置"
//設(shè)置點(diǎn)擊事件
result.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(onSettingClick(recognizer:))))
return result
}()
/// 收藏Item
lazy var collectionView: SettingView = {
let result = SettingView()
result.titleView.text = "收藏"
return result
}()
@objc func onSettingClick(recognizer:UITapGestureRecognizer) {
print("點(diǎn)擊了設(shè)置界面的一個(gè)item")
}
}