调整核心文本选项卡的宽度
我对核心文本相当陌生,但一直相处得很好,但是我在调整选项卡的宽度时遇到了麻烦。
目前,我正在使用我通过查看文档和邮件列表编写的代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想问题是您的所有选项卡都是使用完全相同的位置创建的。每个可能应该是 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.