ThreeLevelAccordian 0.3.0

ThreeLevelAccordian 0.3.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布时间最近发布2017年10月
SwiftSwift版本3.0
SPM支持SPM

Amrata Baghel维护。



  • Amrata Baghel

ThreeLevelAccordian

[![Build Status][build-status-badge]][build-status-url]

ThreeLevelAccordian 是一款适用于 IOS 的三级手风琴组件。其基本代码来源于 SwiftyAccordionCells。设计大多数都是可定制的。支持三级。您可以自定义项目字体、颜色、背景色,并向其添加图片等。最内部的项也可以是多行的。如果某个元素没有任何子元素,则其不会显示展开图标。

alt tag alt tag

alt tag alt tag

示例

要运行示例项目,请克隆仓库,然后首先从 Example 目录中运行 pod install

要求

ios 8.0+

安装

ThreeLevelAccordian 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 即可

pod "ThreeLevelAccordian"

基本用法

There are three types of cells for three levels of Arcadian:
1) TLAHeaderItem: This is the highest level cell.
2) TLACell: This is the second level cell.
3) TLASubItem: This is the innermost cell.

Setup your tableView whichever way you want before initializing ThreeLevelAccordian. If you wish, you can set the background color     and other properties, and they will be retained if you do not override them with options.

Find the basic code below:

import ThreeLevelAccordian

class ViewController: UIViewController, TLADelegate {
    @IBOutlet weak var tableView: UITableView!
        var cells = [TLACell]()
    var delegateController: TLAViewController! //This is very very important

        override func viewDidLoad() {
            super.viewDidLoad()

        //Populating data
        cells.append(TLAHeaderItem(value: "Header1", imageURL: "headerImage1"))
            cells.append(TLACell(value: "Middle item1", imageURL: "cellImage1"))
            cells.append(TLASubItem(value: "Lower item1", imageURL: "subItemImage1"))
            cells.append(TLACell(value: "Middle item2", imageURL: "cellImage2"))
            cells.append(TLASubItem(value: "Lower item2", imageURL: "subItemImage2"))
            cells.append(TLACell(value: "Middle item3", imageURL: "cellImage3"))

        cells.append(TLAHeaderItem(value: "Header2", imageURL: "headerImage2"))
        cells.append(TLACell(value: "Middle item21", imageURL: "cellImage2"))
        cells.append(TLASubItem(value: "Lower item21", imageURL: "subItemImage2"))
        cells.append(TLACell(value: "Middle item22"))

        //Customisation properties..This part is optional
         let options: [TLAOption] = [
                .CellBackgroundColor(UIColor.whiteColor()),
                                    .CellColor(textColor),
                                    .CellFont(UIFont(name: "HelveticaNeue-Medium", size: 14.0)!),
                                    .CellHeight(44.0),
                                    .UseSingleValues(true),

                                   .UseAccessoryIcons(true),
                                   .ExpandIcon(UIImage(named: "MyExpandIcon.png")!),
                                   .CollapseIcon(UIImage(named: "MyCollapseIcon.png")!),
         ]

        //Not optional :) 
        //Specify for cell reuse identifier here
        let threeLevelAccordian = ThreeLevelAccordian.init(cells: cells, options: options, reuseIdentifier:                     "checklistAccordianCell") 
        threeLevelAccordian.delegate = self

        //The next three lines are extremely important
        delegateController = threeLevelAccordian.controller
        tableView.dataSource = delegateController
        tableView.delegate = delegateController

        tableView.reloadData()
    }

    //Delegate function
    func didSelectItemAtIndex(index: Int) {
        let alertController = UIAlertController(title: "Clicked", message: "Clicked \(index)", preferredStyle:                  UIAlertControllerStyle.Alert)
        alertController.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Cancel, handler: nil))
        self.presentViewController(alertController, animated: true, completion: nil)
        }
}

定制

You can either specify single customisation values for all cell types through the parameters given below:
1) CellBackgroundColor
2) CellColor: Text color
3) CellHeight
4) CellFont
If you want to apply these values, make sure you mark UseSingleValues to true

You can also provide cell type specific customisations. The names are self explanatory.
For TLAHeaderItem
1) HeaderTextFont
2) HeaderTextColor
3) HeaderCellBackgroundColor
4) HeaderCellHeight

For TLACell
1) ItemTextFont
2) ItemTextColor
3) ItemCellBackgroundColor
4) ItemCellHeight

For TLASubItem
1) SubItemTextFont
2) SubItemTextColor
3) SubItemCellBackgroundColor
4) SubItemCellHeighti
5) IsMultiline: Mark this as true if you are expecting your text to be too big for a single line.

Also, if you want default styling that comes with tables, you can pass options as nil.  

There is expand and collapse icons shown on default for appropriate rows (that is, if the row can be expanded or needs to be collapsed). You can turn it off or set your own icons for expand or collapse. Parameters for the same are:
1) UseAccessoryIcons: mark false if you do not want to show expand/collapse icons
2) ExpandIcon
3) CollapseIcon

You can use these options as shown in the Basic Usage section.

作者

Amrata Baghel,[email protected]

许可证

ThreeLevelAccordian 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。