iOS UISearchBar學習筆記

來源:互聯網
上載者:User

iOS UISearchBar學習筆記

UISearchBar 是一個搜尋控制項,它提供了一個文本輸入框,一個尋找按鈕,一個書籤按鈕,一個取消按鈕。我們需要使用UISearchBarDelegate代理來進行尋找工作;

拖一個UISearchBar控制項


右側邊欄的屬性<喎?http://www.bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PGltZyBzcmM9"http://www.2cto.com/uploadfile/Collfiles/20141010/2014101008183216.jpg" alt="\">

text 是設定預設的文本,placeholder預留位置也就是文本沒編輯時顯示的文字,prompt是在文字框上面顯示的文字


上面是填寫文本對應的樣子

繼續屬性


這兩個屬性用來設定樣式:



用來設定按鈕;

四個按鈕分別對應的樣式;






我們還能來設定背景圖片:

分別是


上面是用來設定背景圖片的,下面是用來設定(選中上面第四個按鈕scope bar時)的背景圖片




下面來看一下代理:UIBarPositioningDelegate

Editing Text– searchBar:textDidChange://當搜尋內容改變時調用– searchBar:shouldChangeTextInRange:replacementText://這個應該是用後一個文本替換前一個文本範圍– searchBarShouldBeginEditing://使搜尋方塊處於編輯狀態– searchBarTextDidBeginEditing://當使用者開始編輯文本時調用– searchBarShouldEndEditing://使搜尋方塊結束編輯狀態– searchBarTextDidEndEditing://當使用者結束編輯文本時調用Clicking Buttons– searchBarBookmarkButtonClicked://當使用者點擊書籤按鈕時調用– searchBarCancelButtonClicked://當使用者點擊取消按鈕時調用– searchBarSearchButtonClicked://當使用者點擊尋找按鈕時調用– searchBarResultsListButtonClicked://當使用者點擊結果下拉結果清單按鈕時調用Scope Button– searchBar:selectedScopeButtonIndexDidChange://當scope按鈕改變的時候調用



常用的代理方法可以看一下:點擊開啟連結




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.