特定導(dǎo)航欄隱藏
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.delegate = self
}
extension MLMineTableViewController:UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool){
let vcClass = viewController.isKind(of:
MLMineTableViewController.superclass()!)
self.navigationController?.navigationBar.isHidden = vcClass
navigationController.setNavigationBarHidden(vcClass, animated: animated)
}
}
ScrollView,TableView滑動(dòng)鍵盤(pán)隱藏
scrollView.keyboardDismissMode = .OnDrag
or
scrollView.keyboardDismissMode = .Interactive
浮點(diǎn)數(shù)取整
public func ceil(_: Double) -> Double //取上整
public func floor(_: Double) -> Double //取下整
TableView的cell自適應(yīng)高度乾巧,不用單獨(dú)設(shè)置每個(gè)cell的高度
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 200; //預(yù)計(jì)高度
枚舉類(lèi)型
@objc enum DrugStoreType: Int {
case undefined = 0
case online = 1
case offlinee = 2
var text: String {
switch self {
case .online:
return "線上藥店"
case .offlinee:
return "線下藥店"
default:
return ""
}
}
}
let content = DrugStoreType.undefined.text // 直接顯示枚舉對(duì)應(yīng)的文本
泛型
任務(wù):打印輸出數(shù)組內(nèi)所有的元素渐溶。
var stringArray = ["蒼老師", "范老師", "優(yōu)衣庫(kù)"]
var intArray = [1, 3, 4, 5, 6]
var doubleArray = [1.0, 2.0, 3.0]
func printStringArray(a: [String]) {
for s in a {
print(s)
} }
func printIntArray(a: [Int]) {
for i in a {
print(i)
} }
func printDoubleArray(a: [Double]) {for d in a { print(d) } }
簡(jiǎn)介版
func printElementFromArray(a: [T]) {
for element in a {
print(element)
} }