DDAnimatedSwitch 0.0.1

DDAnimatedSwitch 0.0.1

Dmitriy Dotsenko 维护。



  • Dmitriy Dotsenko

自定义动画开关

Platform License Version Carthage compatible Swift 4.2

本框架允许您创建和自定义所有类型的开关。

您可以使用几行代码设置非常复杂或非常简单的开关。

DDAnimatedSwitch

动画开关可以使用任何帧动画。您不仅可以动画化开关,还可以动画化滑块。

动画可以播放、调整大小、循环、加速、减速和反转。

您可以设置任何表单的大小和比例。

DDAnimatedSwitch

该框架提供了大量的动画设置。

更改它们,您可以创建独特且美观的开关。

这里是另一个示例。

DDAnimatedSwitch

除了动画,您还可以创建带有标签或图像的自定义开关。

所有这些元素也可以被动画化和装饰。

DDAnimatedSwitch

请注意!!!

长时间使用该框架可能会导致不可逆的后果。

DDAnimatedSwitch

安装

DDAnimatedSwitch 支持 CocoaPodsCarthage

CocoaPods

要通过 CocoaPods 安装 DDAnimatedSwitch,将以下行添加到您的 Podfile 中

pod 'DDAnimatedSwitch'

在将 CocoaPod 集成到项目中后,使用以下方式导入 DDAnimatedSwitch

import DDAnimatedSwitch

Carthage

要通过 Carthage 安装 DDAnimatedSwitch,将以下行添加到您的 Cartfile 中

github "d-dotsenko/DDAnimatedSwitch"

然后运行

carthage update

手动

DDAnimatedSwitch 文件夹添加到您的 Xcode 项目中。

使用方法

该框架包含几个基本类。每个类都允许您创建和配置特定类型的开关。所有这些类都继承自 DDSwitch 如果您需要一个带有动画标签的自定义开关 - 创建从 DDLabelSwitch 继承的开关

DDAnimatedSwitch

如果您需要带有动画图像的自定义开关 - 创建从 DDImageSwitch 继承的开关

DDAnimatedSwitch

如果您需要一个带有开关和/或滑块的帧动画的自定义开关 - 创建从 DDAnimatedSwitch 继承的开关

DDAnimatedSwitch

如果您只需要一个独特而美丽的开关 - 创建继承自 DDSwitch 的类

DDAnimatedSwitch

查看示例 Xcode 项目。

快速入门

  1. 创建一个新的继承自 DDAnimatedSwitch 的开关

  2. 配置思路,可以参考 DDLabelSwitch 的例子

onTintColor = UIColor.orange
offTintColor = UIColor.lightGray

cornerRadius = 0.5
thumbCornerRadius = 0.5
thumbTintColor = UIColor(red: 0.9, green: 0.9, blue: 0.9, alpha: 1)
padding = frame.size.height / 50
let side = frame.size.height - 2 * padding
thumbSize = CGSize(width: side/2, height: side)
duration = 0.8

thumbShadowColor = UIColor.black
thumbShadowOffset = CGSize(width: 0, height: 0)
thumbShadowRadius = 3
thumbShadowOpacity = 0.7

innerShadowColor = UIColor.black
innerShadowRadius = 7
innerShadowOpacity = 0.5

let labelOn = UILabel()
labelOn...

let labelOff = UILabel()
labelOff...

onLabel = labelOn
offLabel = labelOff

可以参考 DDAnimatedSwitch 的例子

cornerRadius = 0.5
thumbTintColor = UIColor.clear
padding = frame.size.height / 4
let side = frame.size.height / 1.5
thumbSize = CGSize(width: side, height: side)
duration = 0.8

thumbShadowColor = UIColor.white
thumbShadowOffset = CGSize(width: 0, height: 0)
thumbShadowRadius = 10
thumbShadowOpacity = 1

thumbAnimationName = "MoonSunAnimation"         /// --> frame animation name
backgroundAnimationName = "ForestAnimation"     /// --> frame animation name
  1. 如果您想要带有帧动画的开关,您必须创建它。将开关和/或滑块的图像添加到断言(主要包)中。

DDAnimatedSwitch

接下来,创建一个包含每个动画名称的 .plist 文件。

DDAnimatedSwitch

设置 thumbAnimationName 和/或 backgroundAnimationName 为 plist 中的名称。

定制

/// DDSwitch
var isOn: Bool /// The switch value
var animated: Bool /// A Boolean value that determines whether switch changes are animated
var duration: CGFloat /// The animation duration value
var padding: CGFloat /// Minimum left/right thumb offset
var onTintColor: UIColor /// The switch background color if thumb is On
var offTintColor: UIColor /// The switch background color if thumb is Off
var thumbTintColor: UIColor /// The thumb background color
var cornerRadius: CGFloat /// The switch corner radius (0.0 ... 0.5)
var thumbCornerRadius: CGFloat /// The thumb corner radius (0.0 ... 0.5)
var thumbSize: CGSize /// The thumb size
var thumbImage: UIImage? /// The thumb image
var isThumbImageColorAnimate: Bool /// A Boolean value that determines whether thumb imageView tint color is
inversed of the switch background color during animation   switch changes are animated
var thumbShadowColor: UIColor /// The thumb shadow color
var thumbShadowOffset: CGSize /// The thumb shadow offset
var thumbShadowRadius: CGFloat /// The thumb shadow radius
var thumbShadowOpacity: Float /// The thumb shadow opacity
var innerShadowColor: UIColor /// Inner shadow collor of the switch
var innerShadowRadius: CGFloat /// Inner shadow radius of the switch
var innerShadowOpacity: Float /// Inner shadow opacity of the switch

/// DDAnimatedSwitch
var thumbAnimationName: String? /// The name of plist with names of frame images for thumb animation
var backgroundAnimationName: String? /// The name of plist with names of frame images for switch animation 

/// DDLabelSwitch
var onLabel: UILabel? /// The label if thumb is On
var offLabel: UILabel? /// The label if thumb is Off

/// DDImageSwitch
var onImageView: UIImageView? /// The image if thumb is On
var offImageView: UIImageView? /// The image if thumb is Off

要求

  • iOS 9.0
  • Xcode 10,Swift 4.2

许可证

DDAnimatedSwitch 基于 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。