InAppPurchaseButton
一个简单可定制的内购按钮,用 Swift 编写。
安装
最方便的安装方法是使用 Cocoapods 和 Podfile
pod 'InAppPurchaseButton'
或者使用 Carthage 并在 Cartfile
中添加一行
github "PGSSoft/InAppPurchaseButton"
要求
iOS 8.4
使用方法
import InAppPurchaseButton
添加控制项
打开您的故事板或 xib 文件,拖放 UIButton
控件。将自定义类更改为 InAppPurchaseButton
。
添加约束条件
添加约束条件,但请注意,InAppPurchaseButton
会自动改变 内禀内容大小,因此添加高度或宽度等约束可能会导致意外行为。如果您想控制 InAppPurchaseButton
的大小,请查看 minExpandedSize
和 prefferedTitleMargins
属性。
可用状态
InAppPurchaseButton
可能有以下状态:
regular
(active 用于已购买项或 inactive 用于未购买项) - 使用它来显示如 打开(激活状态)或 购买(非激活状态)等文本。
示例:
button.buttonState = .regular(animate: true, intermediateState: .active)
busy
-regular
和downloading
之间的中间状态,通常用于应用程序等待某事物时(例如等待服务器的响应)。
示例:
button.buttonState = .busy(animate: true)
downloading
- 显示当前进度。
示例:
button.buttonState = .downloading(progress: 0.25)
可配置属性
minExpandedSize
- 扩展状态下的最小大小prefferedTitleMargins
- 文本与边缘之间首选空间borderColorForInactiveState
- 非激活状态的边框颜色borderColorForActiveState
- 激活状态的边框颜色backgroundColorForInactiveState
- 非激活状态下按钮的填充颜色backgroundColorForActiveState
- 激活状态下按钮的填充颜色imageForInactiveState
- 非激活状态下按钮的可拉伸背景图片imageForActiveState
- 激活状态下按钮的可拉伸背景图片widthForBusyView
- 显示指示视图时的按钮直径cornerRadiusForExpandedBorder
- 从 .regular 到 .busy 状态转换时边框的圆角borderWidthForBusyView
- .busy 状态的边框宽度borderWidthForProgressView
- .downloading 状态的边框宽度ringColorForProgressView
- 用于 .downloading 状态的环形颜色attributedTextForProgressView
- 用于 .downloading 状态的属性化字符串indicatorImageForProgressMode
- 可显示 .downloading 状态的图像transitionAnimationDuration
- 所有过渡动画的速度shouldAlwaysDisplayBorder
- 表示活动或非活动状态外围是否始终可见或只在过渡期间可见(默认为false)attributedTextForInactiveState
- 用于 .inactive 状态的属性化字符串attributedTextForActiveState
- 用于 .active 状态的属性化字符串
有关更多信息,请参阅 InAppPurchaseButton.swift
文档和示例
贡献
欢迎在 GitHub 上提交问题报告和拉取请求: https://github.com/PGSSoft/InAppPurchaseButton。
许可
该项目在 MIT 许可证规则下作为开源软件提供。
关于
该项目由软件开发机构 PGS Software 维护。查看我们的其他 开源项目 或 联系我们 开发您的产品。