可在 iOS、tvOS、watchOS 和 macOS 上运行
.package(url: "https://github.com/hexagons/Trails.git", from: "1.1.1")
import SwiftUI
import Trails
struct ContentView: View {
var main: Main = Main()
var body: some View {
TrailsView(trailer: main.trailer)
}
}
class Main {
let trailer: Trailer
init() {
let trailCount: Int = 3
let seconds: Double = 10.0
trailer = Trailer(count: trailCount,
duration: seconds)
trailer.circlesActive = true
startTimer()
}
func startTimer() {
let startDate: Date = Date()
let timer: Timer = Timer(timeInterval: 0.5, repeats: true) { _ in
let time: Double = -startDate.timeIntervalSinceNow
let valueA: Double = cos(time)
let valueB: Double = cos(time + (.pi * 2) * (1.0 / 3.0))
let valueC: Double = cos(time + (.pi * 2) * (2.0 / 3.0))
self.trailer.add(valueA, at: 0)
self.trailer.add(valueB, at: 1)
self.trailer.add(valueC, at: 2)
}
RunLoop.current.add(timer, forMode: .common)
}
}
trailer.duration = 10.0
duration 的单位是秒
.duration可以在运行时更改
早于 duration 的时间添加的值将被删除
trailer.circlesActive = true
.circlesActive默认值为false
trailer.circleBorder = false
trailer.circleRadius = 2.0
.circleBorder默认值为true
.circleRadius默认值为3.0
trailer.lineWidth = 3.0
.lineWidth默认值为1.0
trailer.colorsActive = false
当 count 为
1时,.colorsActive默认为false
当 count 为
2或更多时,.colorsActive默认为true
trailer.hues = [0.0, 0.1, 0.2]
色调的数量必须匹配传递给
Trailer的 count
.hues默认为 "rainbow"
色调是
0.0到1.0之间的值,低值:红色到绿色,中间值:绿色到蓝色,高值:蓝色到红色
trailer.colorBlend = false
当
.colorBlend为false时,线条将不会混合。当很多线条重叠时,此选项可见
当
.colorBlend为true时,浅色模式使用.multiply混合,深色模式使用.lighten混合
.colorBlend默认为true
trailer.drawValueEndLines = false
.drawValueEndLines默认为true
trailer.drawValueBackground = false
.drawValueBackground在 iOS 和 watchOS 上默认为true,如果您的背景是透明的,将其设置为false会很有用
trailer.drawDefaultTextBackground = false
.drawValueBackground在 iOS 和 watchOS 上默认为true,如果您的背景是透明的,将其设置为false会很有用
trailer.fontSize = 12.0
.fontSize默认为8.0
trailer.leftSpacing = 10.0
trailer.rightSpacing = 10.0
.leftSpacing和.rightSpacing默认为20.0
要复制本 readme 顶部 gif 中看到的随机性,请使用以下代码
let trailer: Trailer = TrailerMock.make()
由 TrailerMock.swift 提供