哥伦布 1.9.0

Columbus 1.9.0

Stefan Herold 维护。



Columbus 1.9.0

Twitter Follow Version Carthage compatible Platforms Swift Versions iOS 13+ Xcode 13+ Codebeat License Donate

Columbus

国家选择器🌎为 iOS, tvOS 和 watchOS 设计,具有您在许多不同的国家选择器实施中找不到的功能。

功能

  • 使用即时搜索栏筛选国家 - 输入 名称 或其 国家代码
  • 使用右侧的 索引栏 快速查找国家
  • 使用标准组件和 Apple 的 Locale 类进行本地化
  • 支持主题以便轻松适应您的设计
  • 支持Storyboard
  • 从历史选中国家中选择国家 - 仍在进行中

代码文档

在此处找到静态生成的代码文档 这里(由 DocC 提供支持)

安装

Carthage(推荐)

Carthage 是一种去中心化的依赖包管理工具,用于构建您的依赖关系并提供二进制框架。要使用 Carthage 将 Columbus 集成到 Xcode 项目中,请将其在 Cartfile 中指定

github "Blackjacx/Columbus"

使用以下命令构建 XCFramework

carthage bootstrap --use-ssh --use-xcframeworks --cache-builds

与 Cocopods 相比,Carthage 在此框架上有一些优势。由于它需要编译超过 200 个标记资产的资源包,因此使用 Carthage 一次性构建框架并将其添加到您的应用程序中要快得多。如果您使用 Cocoapods,则每次进行清洁构建以及 Xcode 认为需要再次编译 Columbus 时,都会将资源包与 Columbus 一起编译。

CocoaPods

要使用 CocoaPods 安装,只需将以下行添加到 Podfile,然后运行 pod install 安装最新版本

pod "Columbus"

示例

使用说明

以下示例包含 Columbus 所有可能的配置/主题选项。

struct CountryPickerConfig: Configurable {

    var displayState = CountryPickerViewController.DisplayState.countryCodeSelection
    /// In this example this has to be a computed property so the font object
    /// is calculated later on demand. Since this object is created right at app
    /// start something related to dynamic type seems not to be ready yet.
    var textAttributes: [NSAttributedString.Key: Any] {
        [
            .foregroundColor: UIColor.text,
            .font: UIFont.preferredFont(forTextStyle: .body)
        ]
    }
    var backgroundColor: UIColor = .background
    var selectionColor: UIColor = .selection
    var controlColor: UIColor = UIColor(red: 1.0 / 255.0, green: 192.0 / 255.0, blue: 1, alpha: 1)
    var lineColor: UIColor = .line
    var lineWidth: CGFloat = 1.0 / UIScreen.main.scale
    var rasterSize: CGFloat = 10.0
    var separatorInsets: UIEdgeInsets {
        UIEdgeInsets(top: 0, left: rasterSize * 4.7, bottom: 0, right: rasterSize * 2.5)
    }
    let searchBarAttributedPlaceholder: NSAttributedString = {
        NSAttributedString(string: "Search",
                           attributes: [
                            .foregroundColor: UIColor.placeholder,
                            .font: UIFont.preferredFont(forTextStyle: .body)])
    }()
}
let countryPicker = CountryPickerViewController(config: CountryPickerConfig(),
                                                initialCountryCode: "US") { (country) in
    print(country)
}
present(countryPicker, animated: true)

故事板

好消息,我为故事板用户实现了完整的支持。您需要为早期版本提供后备方案。要从故事板实例化选择器,可以使用以下示例

let defaultCountry = CountryPickerViewController.defaultCountry(from: "US")
let picker: CountryPickerViewController = storyboard.instantiateViewController(identifier: "Picker") { (coder) -> CountryPickerViewController? in
    return CountryPickerViewController(coder: coder, initialCountryCode: defaultCountry.isoCountryCode) { (country) in
        print(country)
    }
}

上述示例为CountryPickerViewController提供了一个非可选实例。这种新语法还使我们能够为Storyboard初始化的视图(控制器)提供参数。这可以避免在iOS的早期版本中添加可选属性,这是一个巨大的进步。

iOS

该仓库包含一个示例项目。它展示了该项目的主要用途 - 国籍选择器。要运行它,只需在控制台输入pod try Columbus,它将被下载并为您打开。以下一系列截图突出了 Columbus 的关键特性

筛选 索引栏 历史 本地化 主题
Searchbar Indexbar History Localization Theming

tvOS

...仍在进行中...

watchOS

...仍在进行中...

贡献

  • 如果你发现了 错误,请提交一个 问题
  • 如果你有一个 功能需求,请提交一个 问题
  • 如果你想 贡献力量,请提交一个 有效的Pull Request

作者

Stefan Herold🐦 @Blackjacxxx

贡献者

感谢所有参与其中的人

链接

许可证

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