Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 图中的词包装_Iphone_Ios_Graph_Nsstring_Word Wrap - Fatal编程技术网

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
。其他一切都很好。