Iphone 图中的词包装
我有一个条形图,其中我需要为每个条形写下地名,但有时名称很长。我怎样才能把整个名称和包装是正确的根据酒吧的宽度 我正在使用以下代码Iphone 图中的词包装,iphone,ios,graph,nsstring,word-wrap,Iphone,Ios,Graph,Nsstring,Word Wrap,我有一个条形图,其中我需要为每个条形写下地名,但有时名称很长。我怎样才能把整个名称和包装是正确的根据酒吧的宽度 我正在使用以下代码 NSString *percentage = [NSString stringWithFormat:@"%@",item.myTopNameStr]; [percentage drawAtPoint:CGPointMake(_histogramStartX + 5,_xaxisStart.y - _ySpacingScale*item.yValue - 25)
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];
您是否在
lineBreakMode
中使用了uilinebreakmodewrap
?我尝试了uilinebreakmodewrap
,但我没有得到全名。我想您最好使用–drawInRect:withFont:lineBreakMode:alignment:
;使用sizeWithFont:forWidth:lineBreakMode:
@PeterPajchl:非常感谢,它起作用了。你在linebreakmodewrap
中使用了uilinebreakmodewrap
吗?我试过uilinebreakmodewrap
,但我没有得到全名。我想你最好使用–drawInRect:withFont:lineBreakMode:alignment:
;用sizeWithFont:forWidth:lineBreakMode:
@PeterPajchl:非常感谢,它很有效。我得到的percentageSize.height
=13不够全名,所以我把150
改为percentageSize.height
。其他一切都很好。我得到的是percentageSize.height
=13,这对于全名来说还不够,所以我用150
代替percentageSize.height
。其他一切都很好。