测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2017年10月 |
SwiftSwift版本 | 3.0 |
SPM支持SPM | ✓ |
由Leroy Jenkins和Jelle Vandebeeck维护。
Delirium包含了可以 reused 的一组UI组件。
Delirium通过CocoaPods可用。要安装它,只需将以下行添加到您的Podfile
pod 'Delirium', '~> 2.2'
为您的应用程序添加一些自定义的modal过渡效果。以下是一个这样的过渡效果的示例:
您可以将所有UIBlurEffectStyle
的值传递给ActionTransitioningDelegate
类。以下是实现此过渡的方法:
let transitionDelegate = ActionTransitioningDelegate()
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
transitionDelegate.blurEffectStyle = .Light
transitioningDelegate = transitionDelegate
modalPresentationStyle = .Custom
}
此过渡仅在iOS 9上有效。
您可以使用这个方便的shake
函数对UIView进行震动。
let view: UIView = ...
// Shake the view with the default `duration` of 0.07 seconds and a `repeatCount` of 4.
view.shake()
// You can also pass a custom `duration` or `repeatCount` is wanted.
view.shake(repeatCount: 10, duration: 1.0)
您可以从您的UIViewController
实例中呈现一个NSError
。这将呈现一个带有通过“delirium.alert.button.ok”键翻译的标题的UIAlertController
,并带有来自NSError
的描述localizedDescription
。
以下是一个示例:
以下是实现方法:
let error: NSError = ...
presentAlertController(with: error)
当您想要呈现一个‘ErrorType’时,您必须遵守AlertError
协议。这将确保在警告中显示的ErrorType
有一个标题和描述。
struct SomeError: AlertError {
var title: String { return "Some error occured" }
var description: String { return "This is the reason why some error occured." }
}
let error: SomeError = ...
presentAlertController(with: error)
当您想呈现一个带有重试功能的警报时,可以使用presentAlertController
功能。当实现这个闭包时,您将在警报中看到一个“重试”按钮。当点击此按钮时,将触发闭包。
let error: NSError = ...
presentAlertController(withError: error) {
// Tapped retry.
}
presentAlertController
函数还可以有一个 ok
的回调。当您点击“确认”按钮时,将会触发此回调。
let error: NSError = ...
presentAlertController(withError: error, retry: {
// Tapped retry.
}, ok: {
// Tapped ok.
})
显示一个基本的饼图,饼图有一个简单的叠加层,使设计看起来很干净。
您只需通过在Storyboard中扩展一个UIView
,就可以轻松集成PieChartView
。但对于狂热爱好者来说,您也可以手动创建视图。(就像动物一样)
当视图创建后,您可以添加一些切片。一个切片包含一个值和一个颜色。
let pieChartView = ...
pieChartView.add(slice: PieChartSlice(value: 12.0, color: UIColor.redColor()))
pieChartView.add(slice: PieChartSlice(value: 8.0, color: UIColor.greenColor()))
这将生成一个有两个切片的饼图。红色切片将占据饼图的60%,绿色切片将包含饼图的40%。
您还可以向视图传递一些小的配置选项。
// This is the overlay color of the circle that is drawn over the center of the pie chart. When giving this color an alpha value the pie chart is broken nicely.
pieChartView.overlayColor = UIColor.blueColor()
// This stroke color is the color that is displayed between the slices.
pieChartView.strokeColor = UIColor.blueColor()
// This is the size of the padding from where the overlay circle will be displayed.
pieChartView.overlayPadding = 20.0
使用 Delirium 演示固定视图非常简单。
在Storyboard中派出一个UIView
的子类,并将其设置为PinView
。这个视图将自动计算它自己的固有内容尺寸。因此,在Storyboard中使用固定视图时,您不需要手动设置宽度和高度。请确保固定视图不会被其父视图过分限制。
pinView.delegate = self
当您设置委托为当前控制台时,此控制台需要符合PinViewDelegate
。这意味着应该实现以下方法。
func pinView(view: PinView, didEnterPin pin: String) {
// This method is called whenever your pin code is complete.
// So when the `numberOfDigitis` matched the pin count.
}
您可以向PinView
传递自定义配置。以下是您可以配置的一些选项。
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var keyboardConstraint: KeyboardConstraint! {
didSet {
keyboardConstraint.offsetFromKeyboardHeight = 25
}
}
@IBAction func tapOutsideTextfield(_ sender: UITapGestureRecognizer) {
textField.resignFirstResponder()
}
以下是对所有不同配置选项的概述。
/// Define the size of the buttons.
configuration.buttonSize: CGFloat = 60.0
/// Define the font of the buttons.
configuration.buttonFont = UIFont.systemFont(ofSize: 18.0)
/// Define if you want to see the touch down highlight color.
configuration.allowSelectionFeedback = true
// Define the number of digits you want to enter.
configuration.numberOfDigits = 4
// The title to be displayed in the navigation bar.
configuration.title = "Enter your pin"
// The color of the filled dot at the top of the pin view.
configuration.dotColor = UIColor(red:0.11, green:0.68, blue:0.93, alpha:1.00)
// The color of the stroked dot at the top of the pin view.
configuration.dotStrokeColor = UIColor(red:0.73, green:0.77, blue:0.81, alpha:1.00)
// The color of the stroked pin number button.
configuration.numberStrokeColor = UIColor(red:0.75, green:0.79, blue:0.83, alpha:1.00)
// The color of the highlighted background in the pin number button.
configuration.selectionBackgroundColor = UIColor(red:0.90, green:0.91, blue:0.93, alpha:1.00)
// The color of the background in the pin number button.
configuration.backgroundColor = UIColor.whiteColor()
// The color of the text in the pin number button.
configuration.numberTextColor = UIColor(red:0.01, green:0.13, blue:0.28, alpha:1.00)
/// The color of the stroked clear button.
configuration.clearStrokeColor = UIColor.red
/// The color of the highlighted background in the clear button.
configuration.clearSelectionBackgroundColor = UIColor.lightGray
/// The color of the text in the clear button.
configuration.clearTextColor = UIColor.red
您可以通过向pinView
实例传递configuration
实例来设置配置。
let configuration = PinConfiguration()
pinView.configuration = configuration
只需通过设置布局约束的类来动画化任何视图和键盘的交互。
看这个例子。您不需要实现如下viewcontroller或子类化它。只需使用KeyboardConstraint
类。
感谢Stefan Adams来自iCapps的贡献!
class KeyboardViewController: UIViewController {
@IBOutlet weak var textField: UITextField!
@IBAction func tapOutsideTextfield(_ sender: UITapGestureRecognizer) {
textField.resignFirstResponder()
}
}
extension KeyboardViewController: UITextFieldDelegate {
func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}
当选择类为KeyboardConstraint
的约束时,您可以在Storyboard中设置键盘和您的视图之间的空间量。
通过自定义字体家族,可以轻松使用UIKit的动态类型和文本样式。当在应用中使用动态类型时,您的应用将对iOS设备设置中用户更改的首选文本大小做出反应。
文本样式是一组样式,它使将不同字体大小和粗细放入您的应用变得更容易。例如,标题可能会使用半粗体和17pt大小的点,而正文可能会使用标准粗细和17pt大小的点。
用户未对动态类型进行更改时的默认值是Large
。动态类型从xSmall
到xxxLarge
不等。
可用的参数
family
:用作由 UIFont.familyNames
返回的字体家族名称或应用中嵌入的自定义字体的名称。style
:要使用的字体文本样式。(例如,UIFontTextStyle.headline
)使用示例
// Without using TraitCollection:
let fontFamilyHeitiSC = "Heiti SC"
let font = UIFont.preferredFont(with: fontFamilyHeitiSC, for: .body)
// Using TraitColletion:
let fontFamilyThonburi = "Thonburi"
let anotherFont = UIFont.preferredFont(with: fontFamilyThonburi, for: style, compatibleWith: traitCollection)
// For a list of available fonts use:
print(UIFont.familyNames)
有关动态类型和一般字体的更多信息,请参阅Apple
的网站。
以下是我们的待办事项概述。
UIView
Wiggle。杰勒·范德比克,[邮箱地址可见]
Delirium 可在 MIT 许可证下使用。详细信息请参阅 LICENSE 文件。