FaveButton
Swift 编写的收藏动画按钮
要求
- iOS 8.0+
- Xcode 7.3
安装
对于手动安装,请将资源文件夹拖到您的项目中。
os 使用 CocoaPod,请将以下行添加到您的 Podfile
pod 'FaveButton', '~> 1.2.1' swift 2.2
pod 'FaveButton', '~> 2.0.3' swift 3
对于 Carthage 用户,请将以下行添加到您的 Cartfile
github "xhamr/fave-button"
使用方法
使用 Storyboard 或 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在其App中Dimitris Koutsogiorgas,Danielle Lancashire,Eric Amorde,Orta Therox,Paul Beusterien,Samuel Giddins,以及CocoaPods 开发团队的启发,他们的贡献来自很多人。
许可协议
FaveButton遵循MIT许可协议发布。