我有一个字符串,它比它必须出现的地方的宽度还长。我想要做的是在 2 或 3 行上显示字符串。
我的代码如下:
for (int i=0; i<claimsCount; i++)
{
File_Claim *fileClaim = [claimsArray objectAtIndex:i];
[self checkCreateNewPage:font:10.0];
///////////////////////////////////////////////////////////////////////////////////////
// if the current category is the same as the previous one then don't write it again
///////////////////////////////////////////////////////////////////////////////////////
if ([subcategory isEqualToString:fileClaim.subCategoryName])
{
}
else
{
// hold the old category to check if it is the same
subcategory = fileClaim.subCategoryName;
//HPDF_Page_SetRGBFill (_currentPage, 0, 0, 1);
posY -= PDF_SPACER_Y;
HPDF_Page_TextOut(_currentPage, PDF_BASE_DATA_LABELS_START_X, posY, [fileClaim.subCategoryName cStringUsingEncoding:NSWindowsCP1252StringEncoding]);
}
//HPDF_Page_SetRGBFill (_currentPage, 0, 0, 0);
posY -= PDF_SPACER_Y;
HPDF_Page_TextOut(_currentPage, PDF_BASE_DATA_LABELS_START_X+15, posY, [fileClaim.name cStringUsingEncoding:NSWindowsCP1252StringEncoding]);
HPDF_Page_TextOut(_currentPage, [self alignRightNumberX:fileClaim.unitPrice:260], posY, [[NSString stringWithFormat:@"%.2f €",fileClaim.unitPrice] cStringUsingEncoding:NSWindowsCP1252StringEncoding]);
HPDF_Page_TextOut(_currentPage, 320, posY, [[fileClaim getCalcString] cStringUsingEncoding:NSWindowsCP1252StringEncoding]);
HPDF_Page_TextOut(_currentPage, [self alignRightNumberX:fileClaim.totalPrice:483], posY, [[NSString stringWithFormat:@"%.2f €",fileClaim.totalPrice] cStringUsingEncoding:NSWindowsCP1252StringEncoding]);
}
还有我放置文字的部分:
HPDF_Page_TextOut(_currentPage, PDF_BASE_DATA_LABELS_START_X+15, posY, [fileClaim.name cStringUsingEncoding:NSWindowsCP1252StringEncoding]);
现在这必须出现在 2 或 3 行而不是 1 行上。我不知道该怎么做。
提前致谢
列昂
最佳答案
我已经使用 LibHaru 几天了,我遇到了同样的问题。我开始编写自己的 C 函数来处理换行和多行支持;然后今天我发现 HPDF_Page_TextRect()
实际上可以为您完成这项工作! :)
它会在一个由矩形定义的区域中自动将多行单词包裹起来,它还会返回写入的字符数...
关于iphone - 如何在 iOS 上使用 libharu 以 2/3 行显示字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6689763/