标签:ios swift 搜索框 uisearchbar
转载请声明出处:http://blog.csdn.net/jinnchang/article/details/44827923// // ViewController.swift // UISearchBarSample // // Created by jinnchang on 15/4/1. // Copyright (c) 2015年 Jinn Chang. All rights reserved. // import UIKit class ViewController: UIViewController,UISearchBarDelegate { var searchBar: UISearchBar! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. searchBar = UISearchBar(frame: CGRectMake(0, 20, self.view.frame.size.width, 80)) searchBar.placeholder = "search" searchBar.prompt = "prompt" searchBar.text = "text" searchBar.barStyle = UIBarStyle.Default searchBar.searchBarStyle = UISearchBarStyle.Default searchBar.barTintColor = UIColor.orangeColor() searchBar.tintColor = UIColor.redColor() searchBar.translucent = true searchBar.showsBookmarkButton = true searchBar.showsCancelButton = true searchBar.showsSearchResultsButton = false searchBar.showsScopeBar = false searchBar.delegate = self self.view.addSubview(searchBar) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } // 输入框内容改变触发事件 func searchBar(searchBar: UISearchBar, textDidChange searchText: String) { println("过滤:\(searchText)") } // 书签按钮触发事件 func searchBarBookmarkButtonClicked(searchBar: UISearchBar) { println("搜索历史") } // 取消按钮触发事件 func searchBarCancelButtonClicked(searchBar: UISearchBar) { println("取消搜索") } // 搜索触发事件 func searchBarSearchButtonClicked(searchBar: UISearchBar) { println("开始搜索") } }------------------------------------------------------------------------------------------
文章最后更新时间:2015年4月2日09:35:35。更多资料参考:
UIKit
User Interface Catalog: Search Bars
标签:ios swift 搜索框 uisearchbar
原文地址:http://blog.csdn.net/jinnchang/article/details/44827923