NKButton 4.7.1

NKButton 4.7.1

Nam Kennic 维护。



 
依赖关系
FrameLayoutKit>= 0
NVActivityIndicatorView/AppExtension>= 0
 

NKButton 4.7.1

NKButton

Version License Platform Swift

一个可完全定制的 UIButton

示例

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install

NKButton

安装

NKButton 通过 Swift 包管理器(推荐)和 CocoaPods 可用

pod 'NKButton'

使用方法

创建和基本自定义

let button = NKButton()
button.title = "Button"
button.setTitleColor(.black, for: .normal) // set title color for normal state
button.setTitleColor(.white, for: .highlighted) // set title color for highlight state
button.setTitleFont(normalFont, for: .normal)
button.setTitleFont(boldFont, for: .highlight)
button.setBackgroundColor(.blue, for: .normal) // set background color for normal state
button.setBackgroundColor(.green, for: .highlighted) // set background color for highlight state
button.spacing = 10.0 // space between icon and title
button.imageAlignment = .top // icon alignment
button.underlineTitleDisabled = true // no underline text when `Settings > Accessibility > Button Shapes` is ON
button.isRoundedButton = true
button.cornerRadius = 10.0
button.extendSize = CGSize(width: 50, height: 20) // size that will be included in sizeThatFits

添加边框

button.setBorderColor(.black, for: .normal) // set border color for normal state
button.setBorderColor(.white, for: .highlighted) // set border color for highlight state
button.setBorderSize(1.0, for: .normal) // border stroke size
button.setBorderSize(2.0, for: .highlighted)

添加阴影

button.setShadowColor(.blue, for: .normal) // set shadow color for normal state
button.setShadowColor(.green, for: .highlighted) // set shadow color for highlight state
button.shadowOffset = CGSize(width: 0, height: 5)
button.shadowOpacity = 0.6
button.shadowRadius = 10

添加渐变颜色

button.setGradientColor([UIColor(white: 1.0, alpha: 0.5), UIColor(white: 1.0, alpha: 0.0)], for: .normal) // set gradient color for normal state
button.setGradientColor([UIColor(white: 1.0, alpha: 0.0), UIColor(white: 1.0, alpha: 0.5)], for: .highlighted) // set gradient color for highlight state

设置加载状态

button.loadingIndicatorStyle = .ballBeat // loading indicator style
button.loadingIndicatorAlignment = .atImage // loading indicator alignment
button.hideImageWhileLoading = true
button.hideTitleWhileLoading = false

button.isLoading = true // show loading indicator in the button, and button will be disabled automatically until setting isLoading = false

闪烁

button.startFlashing()
button.startFlashing(flashDuration: 0.25, intensity: 0.9, repeatCount: 10)

下标语法

button.titleColors[.normal] = .black
button.titleFonts[.normal] = normalFont
button.titleFonts[.highlight] = boldFont
button.backgroundColors[.normal] = .white
button.backgroundColors[.highlight] = .yellow
button.borderColors[.normal] = .gray
button.borderColors[[.highlight, .selected]] = .black
button.shadowColors[.normal] = .black

依赖

NKButton 使用 NVActivityIndicatorView 作为加载指示器,因此目前有 32 种动画类型。

NKButton 使用 FrameLayoutKit 来实现内容布局,因此您可以轻松自定义布局。

作者

纳姆·肯尼寇,《[email protected]

许可

NKButton 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。