Es handelt sich um eine Swift-Bibliothek zur Unterstützung des Dropdown-Menüs in iOS
Sehen Sie sich das Video an:
Um das Beispielprojekt auszuführen, klonen Sie das Repo und führen Sie zunächst pod install
aus dem Beispielverzeichnis aus.
Der Swift Package Manager ist ein Tool zur Automatisierung der Verteilung von Swift-Code und ist in den swift
-Compiler integriert.
Sobald Sie Ihr Swift-Paket eingerichtet haben, ist das Hinzufügen von iOSDropDown als Abhängigkeit so einfach wie das Hinzufügen zum dependencies
Wert Ihres Package.swift
.
dependencies: [
. package ( url : " https://github.com/jriosdev/iOSDropDown.git " , . upToNextMajor ( from : " 0.4.0 " ) )
]
Verwenden Sie CocoaPods. iOSDropDown ist über CocoaPods verfügbar. Um es zu installieren, fügen Sie einfach die folgende Zeile zu Ihrem Podfile hinzu:
pod 'iOSDropDown'
zu Ihrer Poddatei hinzu.pod install
ausführen.iOSDropDown.framework
unter „Build-Phasen“ > „Binärdatei mit Bibliotheken verknüpfen“ hinzuimport iOSDropDown
in den .swift-Dateien hinzu, in denen Sie es verwenden möchtenBenutze Karthago.
Cartfile
.github "jriosdev/iOSDropDown"
hinzu.carthage update
aus.iOSDropDown.framework
in Ihr Xcode-Projekt.Klonen Sie einfach die folgenden Swift-Dateien und fügen Sie sie Ihrem Projekt hinzu:
Fügen Sie einfach UITextField zu Ihrem ViewCONtroller hinzu und verbinden Sie @IBOutlet – DropDown-Klasse
@ IBOutlet weak var dropDown : DropDown !
// The list of array to display. Can be changed dynamically
dropDown . optionArray = [ " Option 1 " , " Option 2 " , " Option 3 " ]
//Its Id Values and its optional
dropDown . optionIds = [ 1 , 23 , 54 , 22 ]
// Image Array its optional
dropDown . ImageArray = [ ??? , ? , ? ]
// The the Closure returns Selected Index and String
dropDown . didSelect { ( selectedText , index , id ) in
self . valueLabel . text = " Selected String: ( selectedText ) n index: ( index ) "
}
let dropDown = DropDown ( frame : CGRect ( x : 110 , y : 140 , width : 200 , height : 30 ) ) // set frame
// The list of array to display. Can be changed dynamically
dropDown . optionArray = [ " Option 1 " , " Option 2 " , " Option 3 " ]
// Its Id Values and its optional
dropDown . optionIds = [ 1 , 23 , 54 , 22 ]
// Image Array its optional
dropDown . ImageArray = [ ??? , ? , ? ]
// The the Closure returns Selected Index and String
dropDown . didSelect { ( selectedText , index , id ) in
self . valueLabel . text = " Selected String: ( selectedText ) n index: ( index ) "
}
}
Aktionen
dropDown . showList ( ) // To show the Drop Down Menu
dropDown . hideList ( ) // To hide the Drop Down Menu
Schließungen
listWillAppear ( ) {
//You can Do anything when iOS DropDown willAppear
}
listDidAppear ( ) {
//You can Do anything when iOS DropDown listDidAppear
}
listWillDisappear ( ) {
//You can Do anything when iOS DropDown listWillDisappear
}
listDidDisappear ( ) {
//You can Do anything when iOS DropDown listDidDisappear
}
Benutzerdefinierte Filterfunktion
// overridable function for filter action
func searchFilter ( text : String , searchText : String ) -> Bool {
// you can add custom filter fuctions as your need, like other than english ..etc
}
Sie können diese Eigenschaften des Dropdowns anpassen:
isSearchEnabled
: Sie können DropDown aktivieren oder deaktivieren. Der Standardwert ist true
hideOptionsWhenSelect
: Mit dieser Option wird die Liste ausgeblendet, wenn Sie auf Option 1 klicken. Der Standardwert ist true
selectedRowColor
: Farbe des ausgewählten Zeilenelements in DropDown. Der Standardwert ist .cyan
rowBackgroundColor
: Farbe von DropDown. Der Standardwert ist .white
listHeight
: Die maximale Höhe der Liste. Der Standardwert ist 150
rowHeight
: Die Höhe der Liste in der Liste. Der Standardwert ist 30
selectedIndex
: Zur Vorauswahl eines beliebigen Elements in der ListearrowSize
: Die Größe des Pfeils. Der Standardwert ist 15
arrowColor
: Die Farbe des Pfeils. Der Standardwert ist .black
checkMarkEnabled
: Das Häkchen für die Auswahl der Zeile aktiviert. Der Standardwert ist true
textColor
: Sie können die per DropDown ausgewählte Textfarbe ändernsemanticContentAttribute
: Semantisches Attribut für RTL oder LTRAll Other TextField Properties are available with DropDown
z. B. alignment
“, font
“, textColor
“, „ semanticContentAttribute
“ usw 1.After Update the pod just do clean your buld folder
Product > Clean Build Folder .
Jishnu Raj T, [email protected]
iOSDropDown ist unter der MIT-Lizenz verfügbar. Weitere Informationen finden Sie in der LICENSE-Datei.