需求:我的資產(chǎn) 由三個部分組成尔崔,分別是 可用金額角撞,理財金額呛伴,凍結金額。使用餅圖顯示各個金額所占的比例
在繪制的時候谒所,用到了傳統(tǒng)的方法
UIBezierPath * bezierPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(radius, radius)
radius:88
startAngle:起點
endAngle:終點
clockwise:YES];
在后臺傳輸 三個金額的時候热康,需要算出 各個金額所占的比例,由于存在某個金額過小劣领,在占比中會有忽略的情況姐军。通過查詢資料,了解到了ceill
這個c語言數(shù)學函數(shù)尖淘,向上取值奕锌。比如 CGFloat num = ceil(0.0254155); 結果顯示 num = 1 ;保證了他始終有值。
currentRatio = ceill(self.currentPosition / total*100);
frozenRatio = ceill(self.frozenBalance / total*100);
canUseRatio = 100 - currentRatio - frozenRatio;
效果圖:PieChartView.png
具體代碼:鏈接:https://pan.baidu.com/s/1jp4ZPyICrAVV0ysitZ_dMQ 密碼:y61s
感謝作者 allanGold的博客分享