FaveButton
用 Swift 编写的喜爱的动画按钮
要求
- iOS 8.0+
- Xcode 9+
安装
对于手动安装,将源文件夹拖放到您的项目中。
os 使用 CocoaPod 将此行添加到您自己的 Podfile
中
pod 'FaveButton'
对于 Carthage 用户,将此行添加到您的 Cartfile
中
github "xhamr/fave-button"
使用
带有故事板或 xib 文件
-
创建一个继承自
FaveButton
的按钮 -
为
Normal
状态添加图片 -
将
IBOutlet
委托属性设置为FaveButtonDelegate
的子类 -
可选 修改属性以更改按钮设置
@IBInspectable public var normalColor: UIColor
@IBInspectable public var selectedColor: UIColor
@IBInspectable public var dotFirstColor: UIColor
@IBInspectable public var dotSecondColor: UIColor
@IBInspectable public var circleFromColor: UIColor
@IBInspectable public var circleToColor: UIColor
- 可选 响应委派方法
func faveButton(faveButton: FaveButton, didSelected selected: Bool)
func faveButtonDotColors(faveButton: FaveButton) -> [DotColors]?
代码中
let faveButton = FaveButton(
frame: CGRect(x:200, y:200, width: 44, height: 44),
faveIconNormal: UIImage(named: "heart")
)
faveButton.delegate = self
view.addSubview(faveButton)
操作点颜色
如果您想为点设置不同的颜色,如 Twitter的 心形动画
,则使用目标按钮的委派方法。
func faveButtonDotColors(_ faveButton: FaveButton) -> [DotColors]? {
if faveButton == myFaveButton{
// return dot colors
}
return nil
}
在 FaveButtonDemo 中,您可以找到引起点以此方式出现的一组颜色
致谢
FaveButton受到了Twitter在其应用中使用的“赞”心形动画的启发
许可
FaveButton遵循MIT许可。