有一個柱狀圖標,需要每個柱形圖都顯示名字,但是名字過長的時候就會被蓋住,怎麼解決?我希望能根據字體長度自動調整。
實現代碼:
NSString *percentage = [NSString stringWithFormat:@"%@",item.myTopNameStr];
[percentage drawAtPoint:CGPointMake(_histogramStartX + 5,_xaxisStart.y - _ySpacingScale*item.yValue - 25) forWidth:80 withFont:[UIFont boldSystemFontOfSize:10] lineBreakMode:NSLineBreakByClipping];
效果圖:
NSString * percentage = [NSString stringWithFormat:@"%@",item.myTopNameStr];
CGSize percentageSize = [percentage sizeWithFont:[UIFont boldSystemFontOfSize:10] forWidth:80 lineBreakMode:UILineBreakModeWordWrap];
[percentage drawInRect:CGRectMake(_histogramStartX + 5,_xaxisStart.y - _ySpacingScale*item.yValue - 25, percentageSize.width, percentageSize.height) withFont:[UIFont boldSystemFontOfSize:10] lineBreakMode:UILineBreakModeWordWrap alignment:NSTextAlignmentLeft];