เป็น Swift Library เพื่อรองรับเมนูแบบเลื่อนลงใน iOS
ชมวิดีโอได้ที่:
หากต้องการรันโปรเจ็กต์ตัวอย่าง ให้โคลน repo และรัน pod install
จากไดเร็กทอรีตัวอย่างก่อน
Swift Package Manager เป็นเครื่องมือสำหรับการกระจายโค้ด Swift โดยอัตโนมัติและรวมอยู่ในคอมไพเลอร์ swift
เมื่อคุณตั้งค่าแพ็คเกจ Swift แล้ว การเพิ่ม iOSDropDown เป็นการพึ่งพานั้นทำได้ง่ายพอๆ กับการเพิ่มลงในค่า dependencies
ของ Package.swift
ของคุณ
dependencies: [
. package ( url : " https://github.com/jriosdev/iOSDropDown.git " , . upToNextMajor ( from : " 0.4.0 " ) )
]
ใช้โกโก้พอดส์ iOSDropDown มีให้บริการผ่าน CocoaPods หากต้องการติดตั้ง เพียงเพิ่มบรรทัดต่อไปนี้ใน Podfile ของคุณ:
pod 'iOSDropDown'
ลงใน Podfile ของคุณpod install
iOSDropDown.framework
ใน Build Phases > Link Binary with Librariesimport iOSDropDown
ในไฟล์ .swift ที่คุณต้องการใช้ใช้คาร์เธจ.
Cartfile
.github "jriosdev/iOSDropDown"
carthage update
iOSDropDown.framework
ที่สร้างขึ้นไปยังโปรเจ็กต์ Xcode ของคุณเพียงโคลนและเพิ่มไฟล์ Swift ต่อไปนี้ในโครงการของคุณ:
เพียงเพิ่ม UITextField ให้กับ ViewCOntroller ของคุณและเชื่อมต่อ @IBOutlet - DropDown Class
@ 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 ) "
}
}
การดำเนินการ
dropDown . showList ( ) // To show the Drop Down Menu
dropDown . hideList ( ) // To hide the Drop Down Menu
การปิด
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
}
ฟังก์ชั่นตัวกรองแบบกำหนดเอง
// 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
}
คุณสามารถปรับแต่งคุณสมบัติของดรอปดาวน์เหล่านี้ได้:
isSearchEnabled
: คุณสามารถเปิดหรือปิดการใช้งานบน DropDown ค่าเริ่มต้น เป็น true
hideOptionsWhenSelect
: ตัวเลือกนี้เพื่อซ่อนรายการเมื่อคลิกตัวเลือกหนึ่งรายการ ค่าเริ่มต้นเป็น true
selectedRowColor
: สีของรายการแถวที่เลือกใน DropDown ค่าเริ่มต้นคือ .cyan
rowBackgroundColor
: สีของ DropDown ค่าเริ่มต้นคือ .white
listHeight
: ความสูงสูงสุดของรายการ ค่าเริ่มต้นคือ 150
rowHeight
: ความสูงของรายการในรายการ ค่าเริ่มต้นคือ 30
selectedIndex
:สำหรับการเลือกรายการใดๆ ในรายการล่วงหน้าarrowSize
: ขนาดของลูกศร ค่าเริ่มต้นคือ 15
arrowColor
: สีของลูกศร ค่าเริ่มต้นคือ .black
checkMarkEnabled
: เครื่องหมายถูกเปิดใช้งานสำหรับการเลือกแถว ค่าเริ่มต้นเป็น true
textColor
: คุณสามารถเปลี่ยนสีข้อความที่เลือกแบบ DropDown ได้semanticContentAttribute
: แอตทริบิวต์ความหมายสำหรับ RTL หรือ LTRAll Other TextField Properties are available with DropDown
เช่น alignment
, font
, textColor
, semanticContentAttribute
...etc 1.After Update the pod just do clean your buld folder
Product > Clean Build Folder .
จิษณุ ราช ต. [email protected]
iOSDropDown มีให้บริการภายใต้ใบอนุญาต MIT ดูไฟล์ใบอนุญาตสำหรับข้อมูลเพิ่มเติม