InstrumentUtils_iOS 1.0.9

InstrumentUtils_iOS 1.0.9

测试已测试
语言语言 SwiftSwift
许可证 BSD
发布上次发布2015年9月
SPM支持 SPM

Instrument Marketing, Inc. 维护。



  • Instrument Marketing, Inc. 和 Moses Gunesch

InstrumentUtils_iOS

实用工具是用 Swift 2.0 编写的,可以从 Objective-C 中使用。

EasyFormInput

EasyFormInput

这是一个漂亮的 iOS 文本输入组件,可以处理

  • 单行或多行文本输入
  • 验证电子邮件输入
  • 带有小数和货币选项的数字输入
  • 日期选择
  • 下拉列表选择,具有用于搜索或创建新条目的自动输入选项 EasyFormInput 自动输入选择

组件会在主文本字段中显示输入标题作为提示,并在其下方显示一条线。

当用户点击表单时,下划线会改变颜色,标题变成一个小标题。

您可以配置

  • 字体和文本颜色
  • 日期和数字格式
  • 行色和编辑时的颜色
  • 组件和主要文本周围的填充

组件可以在 UIScrollView 中工作(也可能在 UITableView 中,尽管没有测试过)。包括一个示例项目,其中描述了如何设置必要的 Auto Layout 约束,使用 IB 布局或代码。设置正确后,组件将在滚动视图中平滑地调整大小,当键盘显示时,选中的表单会滚动到视图中。

设置约束需要一些努力,但幸运的是,使用表单组件很简单。设置配置、实例化、检查其值。

单个配置可以方便地重用,因为它是结构体

var config = EasyFormInputConfig()
config.textFont = UIFont(name: "Roboto-Medium", size:12.0)!
config.textColor = UIColor.blackColor()

然后实例化组件

self.emailInput = EasyFormInput(parentView: container1, type: .Email, title: "Email", required:true, configuration: config)

(上述示例中的最后两个参数是可选的。其他可选参数包括 initialValueselectValues)

然后只需使用 value 获取器来检查和检索输入。返回的值的类型将与表单的类型相匹配。

// .Email
if !emailInput.valueIsValid() {
    emailInput.becomeFirstResponder()
    return
}
if let email = emailInput.value as? String {…}

// .Date
if let date = dateInput.value as? NSDate {…}

// .Select
if let teamData = teamInput.value as? [String:String] {…}

// .Select + config.typeInSelectAllowsUnique
if let clientSelection = clientInput.value as? [String:String] {
    // existing item was picked
}
else if let newClientName = clientInput.value as? String {
    // user typed in a unique entry
}

如上所示,valueIsValid() 方法相当基本,当电子邮件无效或留空必填字段时,它将返回 null

如果表单处于未设置状态,返回的 value 将是 null。如果您需要,您还可以查看表单的 rawText 值并检查 stateIsEmptyOrDefault()

更多信息请参见示例项目。

BlockingProgressIndicator

一个简单的带文本字符串显示功能的阻塞式旋转视图。在使用前可以配置字体和文字颜色。

BlockingProgressIndicator

ConstraintsHelpers

用于处理自动布局约束的快捷方法。

extension UIView

// Retrieval
func getSimpleConstraintWithAttribute:
func getConstraintsForOtherView:
func getConstraintForOtherView:withAttribute:

// Removal
func removeAllConstraints:
func removeConstraintsForOtherView:

// Generation
func addConstraintsWithVisualFormat:views:
func addConstraintsWithVisualFormats:views:
func addConstraintForSubview:withVisualFormat:
func addSizeMatchingConstraintsForSubview:
func addSizeMatchingConstraintsForSubview:withMargins:
func addCenteringConstraintsForSubview:
func addSimpleConstraintForAttribute:constant:
func addConstraintForSubview:attribute:toTargetViewAttribute:constant:
func addEqualConstraintForSubview:attribute:
func addEqualConstraintsForSubview:attributes:
func addEqualConstraintForSubview:subviewAttribute attribute:toTargetViewAttribute:
func addEqualConstraintForSubview:otherSubview:attribute:
func addEqualConstraintsForSubview:otherSubview:attributes:
func addEqualConstraintForSubview:attribute:otherSubview:otherAttribute:

// Scroll View Constraints Helpers
func createScrollableContainerViewInScrollView:margins:
func createScrollableContainerView:
func addStackingConstraintsForSubview:subview:topItem:top:edgeMargins:bottomItem:bottom:height:

示例

view.addSizeMatchingConstraintsForSubview(scrimView)
view.addCenteringConstraintsForSubview(spinner)
view.addEqualConstraintForSubview(label, attribute: .CenterX)
view.addEqualConstraintForSubview(label, attribute: .CenterY).constant = 40.0

TwoLineNavBarTitle

在您的UINavigationController的最顶部展示两行文字。在使用前可以配置字体和文字颜色。

// In your view controller:

// Title with smaller subtitle below it
TwoLineNavBarTitle.updateNavBarTitleFor(self, title: titleString,
     subtitle: subtitleString)

// Title that auto-shrinks & word-wraps to 2 lines
TwoLineNavBarTitle.updateNavBarTitleFor(self, title: titleString)

TwoLineNavBarTitle with subtitle

TwoLineNavBarTitle with word-wrap

安装

pod 'InstrumentUtils_iOS'