[TOC]
iOS11 大标题
// 导航控制器的`prefersLargeTitles`为大标题的总开关
navigationController?.navigationBar.prefersLargeTitles = true
// 各个控制器可以自己通过 largeTitleDisplayMode,如果导航控制器的 `prefersLargeTitles` 为 NO,largeTitleDisplayMode 将没有效果
navigationItem.largeTitleDisplayMode = .never

iOS11 导航栏搜索框
let searchResultsVC = SearchResultTabelViewVC(nibName: nil, bundle: nil)
lazy var searchController: UISearchController = {
let vc = UISearchController(searchResultsController: searchResultsVC)
vc.searchResultsUpdater = self.searchResultsVC
vc.hidesNavigationBarDuringPresentation = true
vc.dimsBackgroundDuringPresentation = true
vc.searchBar.placeholder = "搜索设备"
vc.searchBar.enablesReturnKeyAutomatically = false
vc.searchBar.sizeToFit()
return vc
}()
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = false


iOS11 Safe Area Insets
additionalSafeAreaInsets = UIEdgeInsets(top: 100, left: 0, bottom: 100, right: 100)

UITableView separatorInsetReference


tableView.estimatedRowHeight = 0
tableView.estimatedSectionHeaderHeight = 0
tableView.estimatedSectionFooterHeight = 0
tableView.separatorInsetReference = .fromAutomaticInsets
tableView.separatorInset.left = 60
UITableViewCell 左划、右划
// iOS11 UITableViewCell 左划
override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let action = UIContextualAction(style: .normal, title: "收藏") { (action, view, completionHandler) in
// 执行收藏操作
// ...
completionHandler(true)
}
action.image = imageLiteral(resourceName: "favorite")
action.backgroundColor = UIColor.red
let configuration = UISwipeActionsConfiguration(actions: [action])
return configuration
}
// iOS11 UITableViewCell 右划
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let action = UIContextualAction(style: .destructive, title: "删除") { (action, view, completionHandler) in
// remove item
// ...
completionHandler(true)
}
let configuration = UISwipeActionsConfiguration(actions: [action])
return configuration
}
网友评论