segmentController
为了设计《好书》的分类栏,需要用Segment来切换不同的View;这里我们用到了AKSegmentController第三方库:
let buttonArray1 = [
["image":"ledger","title":"文学","font":MY_FONT],
["image":"drama masks","title":"人文社科","font":MY_FONT],
["image":"aperture","title":"生活","font":MY_FONT],
]
self.segmentController1 = AKSegmentedControl(frame: CGRectMake(10,60,SCREEN_WIDTH-20,37))
self.segmentController1?.initButtonWithTitleandImage(buttonArray1)
self.view.addSubview(self.segmentController1!)
首先创建一个按钮数组,再初始化segmentController,并添加进view中。
由于项目中有两个controller,为了避免两个controller的按钮同时按的情况,需要如下代码:
func segmentControllerAction(segment:AKSegmentedControl){
let index = segment.selectedIndexes.firstIndex
print(index)
if segment == self.segmentController1{
self.segmentController2?.setSelectedIndex(3)
}else{
self.segmentController1?.setSelectedIndex(3)
}
}
DropDownMenu
项目中需要点击后可以选择的下拉分类,这里我们用的是IGLDropDownMenu;
先建立点击不同segment后的DropDownMenu分类:
switch (index){
case 0:
self.createDropMenu(self.literatureArray1, array2: self.literatureArray2)
break
case 1:
self.createDropMenu(self.humanitiesArray1, array2: self.humanitiesArray2)
break
case 2:
self.createDropMenu(self.livelihoodArray1, array2: self.livelihoodArray2)
break
case 3:
self.createDropMenu(self.economiesArray1, array2: self.economiesArray2)
break
case 4:
self.createDropMenu(self.technologyArray1, array2: self.technologyArray2)
break
case 5:
self.createDropMenu(self.NetworkArray1, array2: self.NetworkArray2)
break
default:
break
}
其次建立并初始化DropDownMenu:
func createDropMenu(array1:Array,array2:Array){
let dropDownItem1 = NSMutableArray()
for var i = 0;i
不仅如此,还需实现一个dropdownmenu的代理,用于点击以后两边的menubutton均是需要的值:
func dropDownMenu(dropDownMenu: IGLDropDownMenu!, selectedItemAtIndex index: Int) {
if dropDownMenu == self.dropDownMenu1 {
let item = self.dropDownMenu1?.dropDownItems[index] as? IGLDropDownItem
self.detailType = (item?.text)!
self.dropDownMenu2?.menuButton.text = self.detailType
}else{
let item = self.dropDownMenu2?.dropDownItems[index] as? IGLDropDownItem
self.detailType = (item?.text)!
self.dropDownMenu1?.menuButton.text = self.detailType
}
}