LXWaveProgressView 是一個輕量的波浪進度元件,高度、波速、波色都能自訂,適合用在計量儀表、水量提示這類場景。

LXWaveProgressView *progressView1 =
[[LXWaveProgressView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
progressView1.center = CGPointMake(CGRectGetMidX(self.view.bounds), 270);
progressView1.progress = 0.5; // 進度 0 ~ 1
progressView1.waveHeight = 10; // 波高
progressView1.speed = 1.0; // 波速
progressView1.isShowSingleWave = YES; // 是否只顯示單層波
progressView1.firstWaveColor = [UIColor colorWithRed:134/255.0
green:116/255.0
blue:210/255.0
alpha:1];
progressView1.secondWaveColor = [UIColor colorWithRed:134/255.0
green:116/255.0
blue:210/255.0
alpha:0.5];
[self.view addSubview:progressView1];
波iarism本質上是兩條正弦曲線以不同相位水平移動,再包成封閉路徑填色。第二層用半透明並錯開相位,就能得到有層次的水面感。進度變化時只需調整裁剪容器的高度,波形本身不必重算,這樣動畫才會順。
實際效果請直接跑 Demo 看,需求不同就自行調整參數。
Demo 與原文:https://www.jianshu.com/p/0327ea46d1bc