GitHub license Language CocoaPods CocoaPods Carthage compatible

AugmentedButton

UIButton 子类,具有增强的功能

提供的 API

状态的新设置器

每个属性都有其自己的 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 状态设置操作

为按钮上的长按和状态更改添加 target/actions

添加了对两个新的 UIControl.Event 值的支持

使用标准的 target/actions API

augmentedButton.addTarget(self, action: #selector(onLongPress), for: .longPress)
augmentedButton.addTarget(self, action: #selector(buttonStateChanged(_:)), for: .stateChanged)

您可以在此处查看所有公共 API

要求

安装

通过 CocoaPods

安装 AugmentedButton 最简单的方法是通过 CocoaPods。

  1. 将此行添加到您的 Podfile
pod 'AugmentedButton'
  1. 运行 pod install

通过 Carthage

要使用 Carthage 安装 AugmentedButton

  1. 将以下内容添加到您的 Cartfile
github "tapsandswipes/AugmentedButton"
  1. 运行 carthage update
  2. 按照 Carthage Readme 中的描述添加框架

通过 Swift Package Manager

  1. .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")
 	]
)
  1. 运行 swift build

手动

您也可以通过将 Sources 目录的内容复制到您的项目来手动安装它。

联系方式

如果您使用/喜欢 AugmentedButton,请告诉我!

许可证

MIT 许可证

版权所有 (c) 2016 Antonio Cabezuelo Vivo

特此授予许可,对获得本软件及相关文档文件(“软件”)副本的任何人免费,不受限制地处理本软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许向其提供软件的人员在以下条件下这样做

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

本软件按“原样”提供,不提供任何形式的明示或暗示的保证,包括但不限于适销性、特定用途适用性和非侵权性的保证。在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任负责,无论是在合同诉讼、侵权行为或其他方面,由软件或软件的使用或其他交易引起、产生或与之相关。