iOS11新特性

[TOC]

iOS11 大标题

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

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
image.png
image.png

iOS11 Safe Area Insets

additionalSafeAreaInsets = UIEdgeInsets(top: 100, left: 0, bottom: 100, right: 100)
image.png

UITableView separatorInsetReference

image.png

image.png
        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
    }

代码见

https://github.com/action456789/iOS11Demo

你可能感兴趣的:(iOS11新特性)