相关疑难解决方法(0)

在iOS(Swift或Objective-C)中对齐文本而不会破坏跟踪/字距调整/字母间距

见下文:

// Description (HTML string):
var attrStr = NSMutableAttributedString(
    data: formatted.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
    options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
    documentAttributes: nil,
    error: nil)

var paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.Justified
attrStr?.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, attrStr!.length))
attrStr?.addAttribute(NSKernAttributeName, value: -0.1, range: NSMakeRange(0, attrStr!.length))
descLabel.attributedText = attrStr
descLabel.sizeToFit()
Run Code Online (Sandbox Code Playgroud)

到目前为止,我试图证明文本的合理性,导致了同样的行为.我已经通过内联式CSS int eh html文本或使用textAlignment属性尝试过.

问题是,证明文本的合理性会打破字母间距(实际上它会增加每个单词的跟踪/字距,而不是仅增加其间的空间).

看到: 在此输入图像描述

我想看到一个不是黑客的解决方案,因为我已经设计了一些我自己的黑客,但后来我陷入了其他问题的太多可能性.

我错过了一些简单的东西?我已经浏览了所有UI选项,并且在我的代码示例中看到,我甚至尝试更改Kern,它确实发生了变化但只是按比例变化(即它仍然增加).

justify uikit ios

6
推荐指数
1
解决办法
1061
查看次数

标签 统计

ios ×1

justify ×1

uikit ×1