IOS自定義動(dòng)態(tài)柱狀圖

? ? ? ? 之前有一個(gè)需求要求寫一個(gè)柱狀圖,扒了好多代碼沒有合適的,就從code4App上找了一個(gè)稍微有點(diǎn)相似的Demo進(jìn)行了一些修改(時(shí)間有點(diǎn)久,具體demo地址沒有找到),希望對大家有點(diǎn)幫助



簡單的調(diào)用代碼如下:

-(void)creatChart{

? ? JHColumnChart *column = [[JHColumnChart alloc] initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 300)];

? ? column.backgroundColor = [UIColor redColor];

? ? column.valueArr=? @[

?? ? ? ? ? ? ? ? ? ? ? ? @[@10],

?? ? ? ? ? ? ? ? ? ? ? ? @[@20],

?? ? ? ? ? ? ? ? ? ? ? ? @[@8],

?? ? ? ? ? ? ? ? ? ? ? ? @[@50],

?? ? ? ? ? ? ? ? ? ? ? ? @[@22],

?? ? ? ? ? ? ? ? ? ? ? ? @[@34],

?? ? ? ? ? ? ? ? ? ? ? ? @[@9],

?? ? ? ? ? ? ? ? ? ? ? ? @[@22],

?? ? ? ? ? ? ? ? ? ? ? ? @[@34]

?? ? ? ? ? ? ? ? ? ? ? ? ];

? ? column.originSize=CGPointMake(30,30);

}

可設(shè)置的一些屬性:

//峰值

//@property (nonatomic,assign) CGFloat maxHeight1;

//柱狀圖數(shù)組的顏色

@property(nonatomic,strong)NSArray * columnBGcolorsArr;

//y軸的值

@property (nonatomic, strong) NSArray * valueArr;

//整個(gè)大柱狀圖的背景顏色

@property(nonatomic,strong)UIColor? * bgVewBackgoundColor;

//列間距,非連續(xù)的默認(rèn)是5

@property (nonatomic, assign) CGFloat typeSpace;

//圓柱寬度

@property (nonatomic, assign) CGFloat columnWidth;

//是否需要x軸y軸

@property (nonatomic, assign) BOOL needXandYLine;

//y軸虛線指導(dǎo)顏色

@property (nonatomic, strong) UIColor * dashColor;

//左下腳距離x,y的起點(diǎn)

@property (nonatomic, assign) CGPoint originSize;

//外面?zhèn)鬟^來的線的值,轉(zhuǎn)變成在屏幕的位置傳過來

@property (nonatomic, strong)NSArray *jingJieXianArr;

//盛放數(shù)據(jù)數(shù)組? 跟數(shù)據(jù)一對一? 放到另一個(gè)數(shù)組里

@property (nonatomic, strong)NSArray *isKongArr;


? ? //畫警戒線

? ? column.jingJieXianArr=@[@50,@20];

? ? //設(shè)置每個(gè)柱的寬度 默認(rèn)顯示8個(gè)

? ? column.columnWidth=20;

? ? column.typeSpace=20;

? ? column.bgVewBackgoundColor = [UIColor clearColor];

? ? //開始動(dòng)畫

? ? [columnshowAnimation];

? ? [self.viewaddSubview:column];


下面是demo地址,因?yàn)榘凑招枨髮懲曛髲捻?xiàng)目中摳出的一部分,所以有點(diǎn)亂,勿噴,哈哈。。。

鏈接:https://pan.quark.cn/s/6f6aabb6edaa

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容