【问题标题】:Subscript and superscript Strings adding extra space between lines下标和上标字符串在行之间添加额外的空间
【发布时间】:2016-01-22 08:33:23
【问题描述】:

为属性字符串添加下标和上标,使行之间的间隙变得比平时更大。我希望所有的行都等距。

我附上一张截图供参考,由于添加了下标,可以显示前两行和后两行之间的行距差异。

你能帮帮我吗?提前致谢。

if ([start isEqualToString:@"<subscript>"]) {


   [attributedString replaceCharactersInRange:replacingRange withString:tempString];

   [attributedString addAttribute:(NSString *)kCTSuperscriptAttributeName value:@"-1" range:NSMakeRange(startRange.location, tempString.length)];
 }
 if ([start isEqualToString:@"<superscript>"]) {

   [attributedString replaceCharactersInRange:replacingRange withString:tempString];

    NSInteger textheight = 1;
    CFNumberRef subscriptHeight = CFNumberCreate(NULL, kCFNumberNSIntegerType, &textheight);

   [attributedString addAttribute:(NSString *)NSBaselineOffsetAttributeName value:(__bridge id _Nonnull)(subscriptHeight) range:NSMakeRange(startRange.location, tempString.length)];

 }

【问题讨论】:

  • 这是一个声明还是您想要实现的目标? 行间距增加还是您想要增加它们?
  • @luk2302 他试图让它们保持不变。它确实改变了它们出现的线条高度
  • 我已经更新了我的问题

标签: ios objective-c swift nsstring nsattributedstring


【解决方案1】:

用于此的 RTF 标记是“\noextrasprl”。我不知道 UITextView 是否支持它,但您可以尝试将其分配为整个文本的属性(不知道属性键是否需要反斜杠)é

【讨论】:

    猜你喜欢
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    • 2014-03-01
    • 1970-01-01
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多