【问题标题】:iOS 5/6 vs iOS 7 multiline label line spacingiOS 5/6 vs iOS 7 多行标签行间距
【发布时间】:2013-09-28 17:15:19
【问题描述】:

我在 iOS 7 下运行我的应用程序,发现多行标签(非归属的纯文本)以较小的行间距呈现。任何人都知道如何兼容 iOS 5 吗?

iOS 5/6

iOS 7

【问题讨论】:

  • 你找到解决方案了吗?

标签: ios uilabel ios7 core-text textkit


【解决方案1】:
if(NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1)
{
    NSFont *font = /* set font */;

    NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    [paragraphStyle setLineSpacing: /* required line spacing */];

    NSDictionary *attributes = @{ NSFontAttributeName: font, NSParagraphStyleAttributeName: paragraphStyle };
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"strigil" attributes:attributes];

    [label setAttributedText: attributedString];
}
else
{
    /* old method */
}

【讨论】:

  • 如果将行距减少到 0“零”还不够,您应该查看段落样式的“maximumLineHeight”属性。
  • @TwiterZX 降低灯光高度可能会造成某些角色碰撞的问题。
  • @Leo Natan 我同意,如果 maximumLineHeight 低于字体行高,这可能会在文本绘制中产生问题。
  • @Leo Natan 我用它来删除字体下降值,因为它是大写的,所以在这种情况下对我来说是安全的。 "maximumLineHeight = font.ascender"。
  • @SahebSingh 因为我假设alloc] init] 不会返回默认的段落样式。
【解决方案2】:

我在 iOS5/6 中使用了 MSLabel。 iOS7发布后,MSLabel依然正常工作。

iOS5/6 和 iOS7 的标签没有什么不同。 你可以在https://github.com/LemonCake/MSLabel试试MSLabel

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多