Lihat CHANGELOG untuk detailnya
? Tampilan pencarian mengagumkan, ditulis dalam Swift 5.0, muncul tampilan pencarian seperti tampilan Pencarian Pinterest. Anda dapat sepenuhnya menyesuaikan perpustakaan ini. Anda juga dapat menggunakan perpustakaan ini dengan Realm! Lihat penggunaannya di bawah
YNSearch
ditulis dalam Swift 5.0. Kompatibel dengan iOS 8.0+
YNSearch tersedia melalui CocoaPods. Untuk menginstalnya, cukup tambahkan baris berikut ke Podfile Anda:
pod 'YNSearch'
github "younatics/YNSearch"
Tetapkan kategori (wajib) dan riwayat pencarian (opsional)
import YNSearch
let demoDatabase = [ " Menu " , " Animation " , " Transition " , " TableView " , " CollectionView " , " Indicator " , " Alert " , " UIView " , " UITextfield " , " UITableView " , " Swift " , " iOS " , " Android " ]
ynSearch . setCategories ( value : demoDatabase )
ynSearch . setSearchHistories ( value : demoDatabase )
self . ynSearchinit ( )
Atur database (wajib) dan kunci (wajib). kunci akan ditampilkan di YNSearchListView
Anda dapat mengatur database Anda [Any]
jika Anda ingin menyesuaikannya.
let database1 = YNDropDownMenu ( key : " YNDropDownMenu " )
let database2 = YNSearchData ( key : " YNSearchData " )
let demoDatabase = [ database1 , database2 ]
self . initData ( database : demoDatabase )
Tetapkan Delegasi YNSearchListView
func ynSearchListView ( _ ynSearchListView : UITableView , cellForRowAt indexPath : IndexPath ) -> UITableViewCell {
let cell = self . ynSearchView . ynSearchListView . dequeueReusableCell ( withIdentifier : YNSearchListViewCell . ID ) as! YNSearchListViewCell
if let ynmodel = self . ynSearchView . ynSearchListView . searchResultDatabase [ indexPath . row ] as? YNSearchModel {
cell . searchLabel . text = ynmodel . key
}
return cell
}
func ynSearchListView ( _ ynSearchListView : UITableView , didSelectRowAt indexPath : IndexPath ) {
if let ynmodel = self . ynSearchView . ynSearchListView . searchResultDatabase [ indexPath . row ] as? YNSearchModel , let key = ynmodel . key {
// Call listview clicked based on key
self . ynSearchView . ynSearchListView . ynSearchListViewDelegate ? . ynSearchListViewClicked ( key : key )
// return object you set in database
self . ynSearchView . ynSearchListView . ynSearchListViewDelegate ? . ynSearchListViewClicked ( object : self . ynSearchView . ynSearchListView . database [ indexPath . row ] )
// Append Search history
self . ynSearchView . ynSearchListView . ynSearch . appendSearchHistories ( value : key )
}
}
Dapatkan Data Anda dengan Realm
let datas = realm . objects ( RealmModel . self )
Realm bukan tipe koleksi jadi Anda perlu mengonversinya lagi dengan tipe [Any]
. Ini akan menemukan semua string di RealmModel Anda dan menunjukkan hasilnya.
var dataArray = [ Any ] ( )
for data in datas {
let searchModel = RealmModel ( )
searchModel . author = data . author
searchModel . detail = data . detail
searchModel . title = data . title
searchModel . type = data . type
dataArray . append ( searchModel )
}
self . initData ( database : dataArray )
Selesai!
YNSearchViewController: Inherit this viewcontroller
|-- YNSearchTextFieldView: YNSearchTextField with cancel button
| |-- YNSearchTextField: Search UITextfield
| |-- cancelButton: Show when YNSearchTextField textFieldDidBeginEditing
|
|-- YNSearchView : get both YNSearchMainView and YNSearchListView
| |-- YNSearchMainView: First view that you can see
| | |-- categoryLabel: Cateogry label
| | |-- [YNCategoryButton]: cateogory buttons
| | |-- searchHistoryLabel: Search history label
| | |-- [YNSearchHistoryView]: history views
| | | |-- [YNSearchHistoryButton]: Search history button
| | | |-- [closeButton]: Close button
| |
| |-- YNSearchListView: UITableview with search result
atur YNSearchDelegate
jika Anda ingin panggilan balik
self . delegate = self
func ynSearchHistoryButtonClicked ( text : String ) {
print ( text )
}
func ynCategoryButtonClicked ( text : String ) {
print ( text )
}
func ynSearchListViewClicked ( text : String ) {
print ( text )
}
func ynSearchListViewClicked ( object : YNSearchModel ) {
print ( object )
}
Setel jenis YNCategoryButton
.
self . ynSearchView . ynSearchMainView . setYNCategoryButtonType ( type : . colorful )
Lihat penggunaan lainnya di demo
YNSearch
ini berdasarkan hierarki tampilan pemuda
YNSearch tersedia di bawah lisensi MIT. Lihat file LISENSI untuk info lebih lanjut.