调整核心文本选项卡的宽度

发布于 2024-10-11 18:18:34 字数 1083 浏览 4 评论 0原文

我对核心文本相当陌生,但一直相处得很好,但是我在调​​整选项卡的宽度时遇到了麻烦。

目前,我正在使用我通过查看文档和邮件列表编写的代码:

    CFIndex theNumberOfSettings = 1;

    CFIndex i = 0; 
    CTTextTabRef tabArray[1]; 
    CTTextAlignment align = 0; 
    CGFloat location = 80; 
    for (;i < 1; i++ ) { 
        tabArray[i] = CTTextTabCreate( align, location, NULL ); 
    }       
    CFArrayRef tabStops = CFArrayCreate( kCFAllocatorDefault, (const void**) tabArray, 1, &kCFTypeArrayCallBacks );     
    for (;i < 1; i++ ) { CFRelease( tabArray[i] ); } 

    CTParagraphStyleSetting theSettings[1] =
    {
        { kCTParagraphStyleSpecifierTabStops, sizeof(CFArrayRef), &tabStops },
    };

    CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(theSettings, theNumberOfSettings);
    [self.attributedString addAttribute:(NSString *)kCTParagraphStyleAttributeName 
                                  value:(id)paragraphStyle
                                  range:range];

通过设置 location 的值,我可以调整选项卡的宽度,但这仅适用于第一个之后创建的选项卡重置为不同的宽度,相对而言非常小。

它为什么要这样做?

I am fairly new to Core Text but have been getting on well, however I'm having trouble adjusting the width of a tab.

Currently I'm using this code which I have written by looking at the documentation and mailing list:

    CFIndex theNumberOfSettings = 1;

    CFIndex i = 0; 
    CTTextTabRef tabArray[1]; 
    CTTextAlignment align = 0; 
    CGFloat location = 80; 
    for (;i < 1; i++ ) { 
        tabArray[i] = CTTextTabCreate( align, location, NULL ); 
    }       
    CFArrayRef tabStops = CFArrayCreate( kCFAllocatorDefault, (const void**) tabArray, 1, &kCFTypeArrayCallBacks );     
    for (;i < 1; i++ ) { CFRelease( tabArray[i] ); } 

    CTParagraphStyleSetting theSettings[1] =
    {
        { kCTParagraphStyleSpecifierTabStops, sizeof(CFArrayRef), &tabStops },
    };

    CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(theSettings, theNumberOfSettings);
    [self.attributedString addAttribute:(NSString *)kCTParagraphStyleAttributeName 
                                  value:(id)paragraphStyle
                                  range:range];

By setting the value of location I am able to adjust the width of the tab however this only works for the first tab created after that it resets to a different width which is very small comparatively.

Why is it doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何其悲哀 2024-10-18 18:18:34

我想问题是您的所有选项卡都是使用完全相同的位置创建的。每个可能应该是 80 的倍数,而不是正好 80。

I would imagine the issue is all your tabs are created with the exact same location. Each one should probably be a multiple of 80, rather than being exactly 80.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文