AugmentedButton 1.3

AugmentedButton 1.3

测试已测试
Lang语言 SwiftSwift
许可 MIT
发布最后发布2020年3月
SPM支持 SPM

Antonio Cabezuelo Vivo 维护。



  • by
  • Antonio Cabezuelo Vivo

GitHub license Language CocoaPods CocoaPods Carthage compatible

AugmentedButton

具有增强功能的 UIButton 子类

提供的 API

为状态新增设置器

  • backgroundColor
  • tintColor
  • borderColor
  • borderWidth
  • cornerRadius

每个属性都有其自身的 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?

为任何按钮状态设置任何按钮属性

为任何状态设置 UIButton 所支持任何属性的全新 API

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)

要求

  • iOS 8.0+
  • Xcode 8

安装

通过 CocoaPods

使用CocoaPods安装 AugmentedButton 是最简单的方法。

  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

任何人未经限制地使用本软件及其相关文档文件(“软件”)的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本,并允许向软件提供者提供此类软件的人这样做,前提是满足以下条件

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

本软件按“现状”提供,不提供任何形式的保证,包括且不限于对适销性、适用于特定目的和非侵权的保证。在任何情况下,作者或版权持有者对任何索赔、损害或任何其他责任,无论是在合同行为、侵权或其他任何情况下,因软件或对软件的使用或其他任何方式而产生的,概不负责。