iphone - 如何在 iOS 上使用 libharu 以 2/3 行显示字符串?

标签 iphone ios xcode libharu

我有一个字符串,它比它必须出现的地方的宽度还长。我想要做的是在 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/

相关文章:

ios - Multipeer Connectivity Framework - Lost Peer 留在 session 中

ios - 在 objective-c 中创建用于实时音视频广播的rtsp客户端

iOS 左上角后退按钮没有可见的导航栏

iphone - 将 uiview 添加到 uiviewcontroller

iOS Objective-C - 渲染 JBIG2 图像格式

iphone - iPhone 应用程序中基于计时器的提醒

xcode - Git 无法识别在 xcode 项目中添加 .xcscheme 文件

objective-c - 是否可以在不失去其他背景窗口焦点的情况下将焦点集中在 NSPanel 上?

javascript - 使用 Javascript 或 HTML 检测 iOS 设备的型号?

javascript - 如何使用 iPhone SDK 评估 javascript 代码?