IOS11 - UINavigationItem大标题,搜索栏实现
1.新建模型
class Contact: NSObject {
var name : String?
var mobile : String?{
didSet{
if mobile?.lengthOfBytes(using: .utf8) == {
mobileString = mobile
var spaceIndex = mobile?.index(mobile!.startIndex, offsetBy: )
mobileString?.insert(" ", at: spaceIndex!)
spaceIndex = mobile?.index(mobile!.endIndex, offsetBy: -)
mobileString?.insert(" ", at: spaceIndex!)
}
}
}
var address : String?
var email : String?
var mobileString : String?
}
2.搜索控制器
class TestViewController: UIViewController,UISearchResultsUpdating{
func updateSearchResults(for searchController: UISearchController) {
}
var searchResultsCon = ResultsTableViewController()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
}
import UIKit
class ResultsTableViewController: UITableViewController {
var contacts = Array<Contact>()
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return contacts.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "reuseID")
if contacts.count > indexPath.row {
let contact = contacts[indexPath.row]
cell.textLabel!.text = contact.mobileString
}
cell.textLabel!.textColor = UIColor.brown
return cell
}
3.主控制器
class ViewController: UITableViewController,UISearchResultsUpdating{
var searchResultsCon = ResultsTableViewController()
var contacts = Array<Contact>()
override func viewDidLoad() {
super.viewDidLoad()
configureTableView()
configureNavigationBar()
}
func configureTableView(){
tableView.estimatedRowHeight = 44.0
tableView.estimatedSectionHeaderHeight = 0.0
tableView.estimatedSectionFooterHeight = 0.0
for _ in ... {
let temp = Int(arc4random_uniform()) +
let contact = Contact()
contact.mobile = String(temp)
contacts.append(contact)
}
}
func configureNavigationBar(){
if #available(iOS 11.0, *) {
self.navigationController?.navigationBar.prefersLargeTitles = true
//导航栏文本颜色
self.navigationController?.navigationBar.titleTextAttributes = [.foregroundColor:#colorLiteral(red: 0.9254902005, green: 0.2352941185, blue: 0.1019607857, alpha: )]
self.navigationController?.navigationBar.largeTitleTextAttributes = [.foregroundColor:#colorLiteral(red: 0.1764705926, green: 0.4980392158, blue: 0.7568627596, alpha: )]
//search
let mySearchController: UISearchController = UISearchController(searchResultsController: searchResultsCon)
mySearchController.searchResultsUpdater = self
// 设置模态出结果页搜索前不隐藏导航栏
// mySearchController.hidesNavigationBarDuringPresentation = false
self.navigationItem.searchController = mySearchController
// 搜索框默认显示并且滚动不消失
self.navigationItem.hidesSearchBarWhenScrolling = false
//当模态出结果页搜索后不隐藏导航栏
self.definesPresentationContext = true
//刷新控件
tableView.refreshControl = UIRefreshControl()
tableView.refreshControl?.addTarget(self, action: #selector(self.refreshData), for: .valueChanged)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
//MARK -- tableView
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return contacts.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "reuseID")
if contacts.count > indexPath.row {
let contact = contacts[indexPath.row]
cell.textLabel?.text = contact.mobileString
}
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
self.navigationController?.pushViewController(TestViewController(), animated: true)
}
@objc func refreshData(){
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .seconds(), execute: {
self.tableView.refreshControl?.endRefreshing()
})
}
//MARK -- searchController
@available(iOS 8.0, *)
func updateSearchResults(for searchController: UISearchController) {
let searchText = searchController.searchBar.text!
let contactList = contacts.filter({ (con) -> Bool in
return (con.mobile?.hasPrefix(searchText))!
})
searchResultsCon.contacts = contactList
searchResultsCon.tableView.reloadData()
}
override func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
// 搜索框滚动时消失
self.navigationItem.hidesSearchBarWhenScrolling = true
}
}
IOS11 - UINavigationItem大标题,搜索栏实现的更多相关文章
- iOS11 仿大标题 导航栏
iOS11 SytleTitleController 仿大标题 风格 导航栏 仿 iOS11 大导航标题 风格 UI 适用范围 iOS8 + 前言 iOS11全面应用大标题设计,(岂止于大—— 比逼 ...
- word2007二级标题自动编号不从大标题开始的解决方法
今天在编写word文档的时候,遇到一个很奇怪的问题,word2007二级标题自动编号不从大标题开始,可能我说的比较模糊,我截个图大家一看就明白了. 我想要的是2.1 2.2结果,他确是从1.1开始了. ...
- ggplot2画histogram(坐标轴刻度值字体大小,坐标轴标题字体大小,柱形宽度,大标题字体大小、居中)
见链接:https://www.r-bloggers.com/how-to-make-a-histogram-with-ggplot2/ 写的很完整. 此外,关于一些参数的用法: theme(plot ...
- iOS11、iPhone X、Xcode9 适配
更新iOS11后,发现有些地方需要做适配,整理后按照优先级分为以下三类: 1.单纯升级iOS11后造成的变化: 2.Xcode9 打包后造成的变化: 3.iPhoneX的适配 一.单纯升级iOS11后 ...
- iOS之iOS11、iPhone X、Xcode9 适配指南
更新iOS11后,发现有些地方需要做适配,整理后按照优先级分为以下三类: 1.单纯升级iOS11后造成的变化: 2.Xcode9 打包后造成的变化: 3.iPhoneX的适配 一.单纯升级iOS11后 ...
- iOS11、iPhone X、Xcode9 适配指南
更新iOS11后,发现有些地方需要做适配,整理后按照优先级分为以下三类: 1.单纯升级iOS11后造成的变化: 2.Xcode9 打包后造成的变化: 3.iPhoneX的适配 一.单纯升级iOS11后 ...
- 你可能需要为你的APP适配iOS11
WeTest 导读 iOS 11 为整个生态系统的 UI 元素带来了一种更加大胆.动态的新风格. 本文介绍了iOS11在UI方面做了哪些更新,有些更新可以为用户提供更加完美的体验,但也有的可能会给目 ...
- iOS -- iOS11新特性,如何适配iOS11
前言 这几天抽空把WWDC的Session看了一些,总结了一些iOS11新的特性,可能对我们的App有影响,需要我们进行适配.本文作为一个总结. 本文内容包括:集成了搜索的大标题栏.横向选项卡栏.Ma ...
- HTML5学习笔记三 HTML元素、属性、标题、段落简介
一.HTML 元素 HTML 元素以开始标签起始 HTML 元素以结束标签终止 元素的内容是开始标签与结束标签之间的内容 某些 HTML 元素具有空内容(empty content) 空元素在开始标签 ...
随机推荐
- php pack()函数详解与示例
pack和unpack在一般的程序中还真的不容易见到,但是如果你用过很久以前的php生成excel你就会知道了.他的excel的头就是pack出来的最近在尝试与C交互的时候又用上了这玩意,所以不得不再 ...
- etymology-I
1)inter-.intra-.intro- 三个前缀inter-,intra-和intro-还是有差别的. inter-表between,如international那是between differ ...
- Hackerspace
Hackerspace Software - HackerspaceWiki https://wiki.hackerspaces.org/Hackerspace_Software Hackerspac ...
- Windows程序设计(0)——编程之前
Windows程序设计之前 1 做什么 2 解决什么问题 3 有哪些资源 在开始真正的编程之前,需要了解要做的事情是什么,要解决的解决的问题是什么,有哪些资源可以使用. 1 Windows程序设计之前 ...
- Python序列——序列操作
Python中的序列包括,字符串.列表.元组.本文介绍序列的通用操作. 1. 切片中的None >>> s = 'abcdefg' >>> for i in ran ...
- Nginx配置故障转移
当上游服务器(真实访问服务器),一旦出现故障或者是没有及时相应的话,应该直接轮训到下一台服务器,保证服务器的高可用. 如果上游服务器的某一台宕机了,直接轮训到下一个~ 8080 8081 8082 关 ...
- 有哪些逾渗模型percolation?
自wiki 1.第一个研究的模型是伯努利逾渗, 这个模型中所有键bond独立,物理学家称为键逾渗. 2.随机聚类模型,同Ising模型和Potts模型有很多联系 3.在完备图上的键逾渗,属于在随机图上 ...
- linuxshell,闲散命令记录
1. 移动光标到 0:0 位置 printf "\033[0;0H" 2. 清屏 printf "\033[2J" 3. awk接收 外部变量 awk -v v ...
- 关于 josnp ,解决跨域问题
JSONP是服务器与客户端跨源通信的常用方法.最大特点就是简单适用,老式浏览器全部支持,服务器不用做任何改造[使用jsonp的时候jsonp: "callback",callbac ...
- 谈谈java中静态变量与静态方法在有继承关系的两个类中调用
谈谈java中静态变量与静态方法在有继承关系的两个类中调用 学习的中如果遇到不明白或者不清楚的的时候,就是自己做些测试,自己去试试,这次我就做一个关于静态变量和静态方法在有继承关系的两个类中的问题测试 ...