1、狀態欄反色
a.在info中添加View controller-based status bar appearance,並將值設置 NO,表明不由系統控制,由vc自己控制;
b.在viewWillApear中使用以下代碼實現反色
UIApplication.shared.setStatusBarStyle(UIStatusBarStyle.lightContent, animated: true) //UIApplication.shared.statusBarStyle = .lightContent
UIApplication.shared.setStatusBarStyle(UIStatusBarStyle.default, animated: true) //UIApplication.shared.statusBarStyle = .default
2、導航條透明以及文字顏色、其他按鈕顏色
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white]
self.navigationController?.navigationBar.tintColor = UIColor.white self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.black]
self.navigationController?.navigationBar.tintColor = UIColor.black
3、鎖定屏幕方向
a.在AppDelegate中實現
func application(_ application: UIApplication, supportedInterfaceOrientationsFor Window: UIWindow?) -> UIInterfaceOrientationMask {
if !self.blockRotation {
return UIInterfaceOrientationMask.all
} else {
return UIInterfaceOrientationMask.portrait
}
}
var blockRotation: Bool = falseextension UIViewController {
var app : AppDelegate {
return UIApplication.shared.delegate as! AppDelegate
}
} app.blockRotation = true
old = UIDevice.current.value(forKey: "orientation")
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")app.blockRotation = false
以上整理內容在xcode 8.2.1(8C1002)中,用swift3實現,希望對各位有幫助,不用東奔西跑了。
以上就是奔五的人學IOS:swift對 狀態欄、導航條若干技巧的全文介紹,希望對您學習和使用IOS應用開發有所幫助.【奔五的人學iOS:swift對 狀態欄、導航條若干技巧】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!