UIButton 子类,具有增强的功能
每个属性都有其自己的 API,形式为
func setXxx(_ value: Value, for state: UIControl.State)
func xxx(for state: UIControlState) -> Value
func currentXxx() -> Value
其中 Value
等于 UIButton
中每个属性的类型。 例如,对于 backgroundColor
,API 是
func setBackgroundColor(_ color: UIColor?, for state: UIControl.State)
func backgroundColor(for state: UIControl.State) -> UIColor?
func currentBackgroundColor() -> UIColor?
新的 API,用于为任何状态设置 UIButton 支持的任何属性
func setValue<Value>(_: Value, forKeyPath: ReferenceWritableKeyPath<AugmentedButton, Value>, for: UIControl.State)
func valueForKeyPath<Value>(_: KeyPath<AugmentedButton, Value>, for: UIControl.State) -> Value?
func currentValueForKeyPath<Value>(_: KeyPath<AugmentedButton, Value>) -> Value
func setActions(_ block: @escaping (AugmentedButton) -> Void, named name: String? = default, for state: UIControl.State)
如果您希望重置操作,请始终为 .normal
状态设置操作
添加了对两个新的 UIControl.Event
值的支持
.stateChanged
用于按钮状态属性的任何更改.longPress
用于按钮上的长按手势使用标准的 target/actions API
augmentedButton.addTarget(self, action: #selector(onLongPress), for: .longPress)
augmentedButton.addTarget(self, action: #selector(buttonStateChanged(_:)), for: .stateChanged)
您可以在此处查看所有公共 API
安装 AugmentedButton 最简单的方法是通过 CocoaPods。
pod 'AugmentedButton'
pod install
。要使用 Carthage 安装 AugmentedButton。
github "tapsandswipes/AugmentedButton"
carthage update
.Package(url: "https://github.com/tapsandswipes/AugmentedButton.git", "1.3")
添加到您的 Package.swift
中的 dependencies
import PackageDescription
let package = Package(
name: "yourapp",
dependencies: [
.Package(url: "https://github.com/tapsandswipes/AugmentedButton.git", "1.3")
]
)
swift build
。您也可以通过将 Sources
目录的内容复制到您的项目来手动安装它。
如果您使用/喜欢 AugmentedButton,请告诉我!
版权所有 (c) 2016 Antonio Cabezuelo Vivo
特此授予许可,对获得本软件及相关文档文件(“软件”)副本的任何人免费,不受限制地处理本软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许向其提供软件的人员在以下条件下这样做
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
本软件按“原样”提供,不提供任何形式的明示或暗示的保证,包括但不限于适销性、特定用途适用性和非侵权性的保证。在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任负责,无论是在合同诉讼、侵权行为或其他方面,由软件或软件的使用或其他交易引起、产生或与之相关。