UIStoryboard
//1.通過stroyboard獲取控制器
let childVc = UIStoryboard(name: "Home", bundle: nil).instantiateInitialViewController()!
頂部導(dǎo)航欄UIBarButtonItem
controller繼承UIViewController,子類有navigationItem(UINavigationItem)
let btn = UIButton()
btn.setImage(UIImage(named: "logo"), for: UIControl.State.normal)//logo是圖片資源名
//swift的圖片資源不用寫路徑名,要求圖片資源唯一
頂部導(dǎo)航欄左邊按鈕:navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
頂部導(dǎo)航欄右邊按鈕數(shù)組navigationItem.rightBarButtonItems = []
UITapGestureRecognizer:
假如你想要在你的應(yīng)用中檢測手勢瘟判,例如點(diǎn)擊,縮放角溃,平移拷获,或者旋轉(zhuǎn),用Swift和內(nèi)建的UIGestureRecognizer類實(shí)現(xiàn)是非常容易的
let tapGes = UITapGestureRecognizer(target: self, action: #selector(self.titleLabelClick(tagGes:)))
label.addGestureRecognizer(tapGes)
//獲取手勢所在view
@objc private func titleLabelClick(tagGes: UITapGestureRecognizer){
guard let currentLabel = tagGes.view as? UILabel else {return}
}
//獲取位置
func picTap(sender: UITapGestureRecognizer) { ???????
????????let point = sender.location(in: sender.view)
}
alert對話框
注意,最后要present才會彈出對話框,然后是一個alertController里面加alertAction,可以有多個alertAction
let alertController = UIAlertController(title:"提示", message:"學(xué)生賬號注冊暫未開放z", preferredStyle: .alert)
let alertOK = UIAlertAction(title: "好的", style: .cancel, handler:nil)
alertController.addAction(alertOK)
present(alertController, animated:true, completion: nil)
UITextField
UITextField加placeholder:
textField.attributedPlaceholder = NSAttributedString.init(string:"請輸入用戶名", attributes: [
????????????NSAttributedString.Key.foregroundColor:UIColor.lightGray])