SwiftMultiSelect 0.2.4

SwiftMultiSelect 0.2.4

测试已测试
语言语言 SwiftSwift
许可 MIT
发布上次发布2018年1月
SwiftSwift 版本3.0
SPM支持 SPM

LucaBecchetti 维护。



  • Luca Becchetti

SwiftMultiSelect - 一个带有图形多选择的 tableView(来自联系人通讯录或自定义列表中的条目

SwiftMultiSelect

在我的应用程序开发过程中,我通常需要从 tableView 中选择多个元素,但我不喜欢原生 iOS 集成,我认为它没有图形上的清晰性,所以我创建了这样一个库。为您的下一个项目选择 SwiftMultiSelect,我很乐意为您提供一点帮助!

★★ 在我们的 GitHub 仓库上给我们 starred ,或者 ☕ 支付我一杯咖啡 ★★

Luca Becchetti 创建

屏幕截图

我们支持纵向和横向屏幕方向

simulator screen shot 28 lug 2017 11 32 34

要求

  • iOS 9+
  • swift 3.0

主要功能

以下是您可以在 SwiftMultiSelect 中找到的主要功能的一些亮点

  • 访问通讯录或自定义列表 从通讯录或自定义列表中选择联系人
  • 快速流畅的滚动.
  • 多方向 我们支持 portraitelandscape 方向
  • 完全可自定义。您可以程序化地自定义所有内容

你也可能会喜欢

你喜欢 SwiftMultiSelect 吗?我还在开发几个其他的开源库。

请查看此处

Podfile

要使用 CocoaPods 将 SwiftMultiSelect 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

target 'TargetName' do
  use_frameworks!
  pod 'SwiftMultiSelect'
end

然后,运行以下命令

$ pod install

如何使用

首先在您的项目中导入库

import SwiftMultiSelect

该库可以显示来自电话簿或自定义列表的元素,这由配置变量“dataSourceType”定义,它可以从SwiftMultiSelectSourceType“枚举”中取值,默认为“phone”。

/// (default) use a contact from PhoneBook, (need a string in info.plist)
SwiftMultiSelect.dataSourceType = .phone

/// (default) use items from custom list, (need to implement a datasource protocol)
SwiftMultiSelect.dataSourceType = .custom

使用电话簿联系人

注意:如果您想使用默认值“phone”,请在您的info.plist文件中插入此字符串

<dict>
    
  .....
  
    <key>NSContactsUsageDescription</key>
    <string>This app needs access to contacts.</string>
  
  ....
  
</dict>

显示简单多选的基本代码如下

//Implement delegate in your UIViewController
class ViewController: UIViewController,SwiftMultiSelectDelegate {
  
  override func viewDidLoad() {
        
        super.viewDidLoad()
      
        //Register delegate
        SwiftMultiSelect.delegate       = self
    
  }

  //MARK: - SwiftMultiSelectDelegate
    
    //User write something in searchbar
    func userDidSearch(searchString: String) {
        
        print("User is looking for: \(searchString)")
        
    }

    //User did unselect an item
    func swiftMultiSelect(didUnselectItem item: SwiftMultiSelectItem) {
        print("row: \(item.title) has been deselected!")
    }

    //User did select an item
    func swiftMultiSelect(didSelectItem item: SwiftMultiSelectItem) {
        print("item: \(item.title) has been selected!")
    }

    //User did close controller with no selection
    func didCloseSwiftMultiSelect() {
        print("no items selected")
    }

    //User completed selection
    func swiftMultiSelect(didSelectItems items: [SwiftMultiSelectItem]) {

        print("you have been selected: \(items.count) items!")
        
        for item in items{
            print(item.string)
        }
        
    }
  
}

显示控制器

现在,在代码的某个地方,使用

   SwiftMultiSelect.Show(to: self)

使用SwiftMultiSelectItem的自定义列表

创建SwiftMultiSelectItem对象

此库只能显示“SwiftMultiSelectItem”对象数组,您可以为它的初始化器传递多个参数

let item = SwiftMultiSelectItem(
        //An incremental unique identifier
        row         : 0,
        //Title for first line
        title       : "Item 0",
        //Description line
        description : "i am description 0",
        //Image asset, shown if no imageURL has been set
        image       : UIImage(),
        //Url of remote image
        imageURL    : "",
        //Custom color, if not present a random color will be assigned
        color       : UIColor.gray
        //Your custom data, Any object
        userInfo    : ["id" : 10]
)

实现dataSource协议

为了传递您的SwiftMultiSelectItem列表,您必须实现SwiftMultiSelectDataSource

//Implement delegate in your UIViewController
class ViewController: UIViewController,SwiftMultiSelectDelegate,SwiftMultiSelectDataSource {

  //Declare list to use
  var items:[SwiftMultiSelectItem] = [SwiftMultiSelectItem]()
  
  override func viewDidLoad() {
        
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        //Generate items
        createItems()
       
        //Se the correct data source type
        SwiftMultiSelect.dataSourceType = .custom
        
        //Register delegate
        SwiftMultiSelect.dataSource     = self
        SwiftMultiSelect.delegate       = self
        
    }
    
    //MARK: - SwiftMultiSelectDataSource
    
    func numberOfItemsInSwiftMultiSelect() -> Int {
        return selectedItems.count
    }
    
    func swiftMultiSelect(itemAtRow row: Int) -> SwiftMultiSelectItem {
        return selectedItems[row]
    }
    

}

与通知交互

要与控制器交互,您有一个代理类和数据源类

/// A data source
public protocol SwiftMultiSelectDataSource{
    
    /// Ask datasource for current item in row
    func swiftMultiSelect(itemAtRow row:Int) -> SwiftMultiSelectItem
    
    /// Asks datasource for the number of items
    func numberOfItemsInSwiftMultiSelect() -> Int
    
}

/// A delegate
public protocol SwiftMultiSelectDelegate{
    
    /// Called when user did end selection
    func swiftMultiSelect(didSelectItems items:[SwiftMultiSelectItem])
    
    /// Called when user has been selected an item
    func swiftMultiSelect(didSelectItem item:SwiftMultiSelectItem)
    
    /// Called when user has been unselected an item
    func swiftMultiSelect(didUnselectItem item:SwiftMultiSelectItem)
    
    /// Called when user has been closed with no selection
    func didCloseSwiftMultiSelect()
    
    /// Called when user did write in searchbar
    func userDidSearch(searchString:String)   
}

自定义

SwiftMultiSelect是完全可定制的,要对其进行配置,您必须修改该Config结构体

/// Public struct for configuration and customizations
public struct Config {

    /// Background of main view
    public static var mainBackground        :   UIColor    = UIColor.white
    /// View's title
    public static var viewTitle             :   String     = "Swift Multiple Select"
    /// Title for done button
    public static var doneString            :   String     = "Done"
    //Placeholder image during lazy load
    public static var placeholder_image     :   UIImage     = SwiftMultiSelect.image(named: "user_blank")!
    /// Array of colors to use in initials
    public static var colorArray        :   [UIColor]  = [
        ThemeColors.amethystColor,
        ThemeColors.asbestosColor,
        ThemeColors.emeraldColor,
        ThemeColors.peterRiverColor,
        ThemeColors.pomegranateColor,
        ThemeColors.pumpkinColor,
        ThemeColors.sunflowerColor
    ]
    
    /// Define the style of tableview
    public struct tableStyle{
        
        //Background color of tableview
        public static var backgroundColor       :   UIColor = .white
        //Height of single row
        public static var tableRowHeight        :   Double  = 70.0
        //Margin between imageavatar and cell borders
        public static var avatarMargin          :   Double  = 7.0
        //Color for title label, first line
        public static var title_color           :   UIColor = .black
        //Font for title label
        public static var title_font            :   UIFont  = UIFont.boldSystemFont(ofSize: 16.0)
        //Color for description label, first line
        public static var description_color     :   UIColor = .gray
        //Font for description label
        public static var description_font      :   UIFont  = UIFont.systemFont(ofSize: 13.0)
        //Color for initials label
        public static var initials_color        :   UIColor = .white
        //Font for initials label
        public static var initials_font         :   UIFont  = UIFont.systemFont(ofSize: 18.0)

    }
    
    /// Define the style of scrollview
    public struct selectorStyle{
        
        //Image asset for remove button
        public static var removeButtonImage     :   UIImage = SwiftMultiSelect.image(named: "remove")!
        //The height of selectorview, all subviews will be resized
        public static var selectionHeight       :   Double  = 90.0
        //Scale factor for size of imageavatar based on cell size
        public static var avatarScale           :   Double  = 1.7
        //Color for separator line between scrollview and tableview
        public static var separatorColor        :   UIColor = UIColor.lightGray
        //Height for separator line between scrollview and tableview
        public static var separatorHeight       :   Double  = 0.7
        //Background color of uiscrollview
        public static var backgroundColor       :   UIColor = .white
        //Color for title label
        public static var title_color           :   UIColor = .black
         //Font for title label
        public static var title_font            :   UIFont  = UIFont.systemFont(ofSize: 11.0)
        //Color for initials label
        public static var initials_color        :   UIColor = .white
        //Font for initials label
        public static var initials_font         :   UIFont  = UIFont.systemFont(ofSize: 18.0)
        //Background color of collectionviewcell
        public static var backgroundCellColor   :   UIColor = .clear
        
    }

}

您可以在显示控制器之前设置变量,例如在ViewDidLoad中

override func viewDidLoad() {
        
        super.viewDidLoad()
        
        // Do any additional setup
        Config.doneString = "Ok"
        
        SwiftMultiSelect.dataSource     = self
        SwiftMultiSelect.delegate       = self
        
}

使用SwiftMultiSelect的项目

您的应用和SwiftMultiSelect

我对列出使用此库的所有项目感兴趣。请自由在GitHub上创建一个带有您的项目名称和链接的Issue;我们将将其添加到本站。

致谢 & 许可证

SwiftMultiSelect由Luca Becchetti拥有和维护

作为开源作品,任何帮助都受欢迎!

此库的代码根据MIT许可证授权;您可以在商业产品中无限制地使用它。

唯一的要求是在您的致谢/关于部分添加一行以下文本

In app notification by SwiftMultiSelect - http://www.lucabecchetti.com
Created by Becchetti Luca and licensed under MIT License.

关于我

我是一名专业程序员,从事软件设计和开发,目前在名为“Frind”的创业公司担任项目经理和iOS高级软件工程师,正在开发我的定性技能。

我在软件开发(10多年前就有经验)方面技能高超,从小就是网络管理员,并是一名资深的PHP开发者。在过去的几年里,我努力从事移动应用程序编程、iOS世界的Swift和Android世界的Java。

我是一名资深的移动开发者和架构师,拥有多年的团队管理、设计和开发主要移动平台(iOS、Android,3年以上经验)的经验。

我也有广泛的网页设计和开发经验,包括客户端、服务器端以及API/网络设计。

我所有的最后一项工作都托管在AWS亚马逊云上,我能够配置网络和Unix服务器。对于我的最后一项工作,我配置了Apache2、SSL、ejabberd集群模式、带负载均衡器的API服务器等等。

我住在意大利的阿西西(佩鲁贾),一个小镇,关于任何问题,请联系我