iphone - 如何使用 swift 更改 UICell 上字母和线条之间的间距

标签 iphone xcode swift uitableview

enter image description here

我正在使用自定义表格 View 单元格并动态调整它们的大小以适合它们的内容(使用 UICell 上的约束),但我无法控制字母和线条之间的间距,我正在使用此代码

   let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = 40

        var attrString = NSMutableAttributedString(string: str!)
        attrString.addAttribute(NSParagraphStyleAttributeName, value:paragraphStyle, range:NSMakeRange(0, attrString.length))

最佳答案

对于 objective-c 中字母之间的间距:

NSAttributedString * attributedString =
    [[NSAttributedString alloc]
     initWithString:text
     attributes: @{ NSKernAttributeName : @(1.20f) }];

    label.attributedText = attributedString;

1.20f 是您希望字母之间的间距。标签是一个 UILabel

swift :

http://rajiev.com/ios-font-kerning-with-swift-and-nsattributedstring/

关于iphone - 如何使用 swift 更改 UICell 上字母和线条之间的间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34874018/

相关文章:

ios - 如何在 iOS 中识别使用来自 esim 或物理 sim 的移动数据的用户

iphone - SBJSON 解析器在第二次尝试时不起作用

iphone - 如何删除 UITabBarItem 下面的空间

iphone - 使用翻转过渡更改 leftBarButtonItem?

xcode - 不能 Git Blame 文件

c++ - 在 xcode 中配置 freeimage

ios - 如何让stackview在向下滚动时消失,向上滚动时重新出现?

objective-c - 在遍历 NSDictionary 时处理不同的对象类型

swift - 如何在 MacOS 应用程序中执行 Apple Finder -> 文件信息 -> 添加标签功能?

swift - 如何在 SpriteKit (Swift) 中获取施加在对象上的力