Particles
Particles是particles.js的原生Swift版本,受此StackOverflow问题的启发。
安装
Particles
通过 CocoaPods 提供。要安装它,只需将以下行添加到您的Podfile中
pod 'Particles'
用法
您必须导入Particles
包。
import Particles
let particlesView = ParticlesView(frame: view.frame)
view.addSubview(particlesView)
您还可以用三个可选参数初始化ParticlesView
var bgColor: UIColor = .clear // The color of the background of the view
var particlesColor: UIColor = .black // The color of the particles and the lines connecting them
var density: ParticleDensity = .extraLight // How densely packed the view is with particles
var speed: ParticleSpeed = .normal // How fast the particles are moving
ParticleDensity
枚举有五个情况
.extraLight
.light
.normal
.dense
.extraDense
ParticleSpeed
枚举有三个情况
.quick
.normal
.slow
bgColor
、particlesColor
、density
和speed
可以在初始化后更改。更改密度不会导致粒子重新发射,但会根据新的density
添加或删除所需的粒子数量。
示例
在ParticlesExample目标中提供了一个示例项目,以演示其功能。
默认的ParticlesView
看起来像这样(具有黑色背景和白色粒子颜色)
可根据您的具体喜好进行定制,例如像这样(蓝色背景和红色粒子颜色)
许可证
《粒子》遵循MIT许可证。