Swift 3 NSMutableParagraphStyle : NSLineBreakMode.byWordWrapping 继续打断文字
Swift 3 NSMutableParagraphStyle : NSLineBreakMode.byWordWrapping keep breaking the words
我有一个应用于 NSMutableAttributedString 的 NSMutableParagraphStyle 样式:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let myString = "Before a telephone call, I need to go to the bathroom..."
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineBreakMode = NSLineBreakMode.byWordWrapping
let myMutableString = NSMutableAttributedString(
string: myString,
attributes: [
NSFontAttributeName:UIFont(
name: "Georgia",
size: 45.0
)!,
NSParagraphStyleAttributeName: paragraphStyle
]
)
let textView = UITextView( frame: CGRect(
x: 20,
y: 25,
width: 260,
height: 400
) )
textView.attributedText = myMutableString
self.view.addSubview( textView )
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
但是当我将那个可变字符串添加到 UITextView 时,它一直在破坏文字。
我去paragraphStyle.lineBreakMode = NSLineBreakMode.byCharWrapping
的时候break没有出现在同一个地方...所以它确实有效果。但这仍然是片面的。我有单词 «call» 在 «c» 之后中断,这太奇怪了。
我可以在故事板编辑器中重现它:
这是预期的行为。根据 Apple 的文档,
byWordWrapping
Wrapping occurs at word boundaries, unless the word
itself doesn’t fit on a single line. See Characters and Grapheme
Clusters in String Programming Guide for a discussion of issues
related to determining word boundaries.
byCharWrapping
Wrapping occurs before the first character that doesn’t fit.
更多信息请参考Apple's Documentation
Aaaaaannnnddd 解决方案是尝试在 sublime text 中编辑我的代码,并意识到电话和电话之间存在不可破坏的 space。
这似乎是一个非常愚蠢的基本功能。为什么 Xcode 不能告诉我...
我有一个应用于 NSMutableAttributedString 的 NSMutableParagraphStyle 样式:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let myString = "Before a telephone call, I need to go to the bathroom..."
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineBreakMode = NSLineBreakMode.byWordWrapping
let myMutableString = NSMutableAttributedString(
string: myString,
attributes: [
NSFontAttributeName:UIFont(
name: "Georgia",
size: 45.0
)!,
NSParagraphStyleAttributeName: paragraphStyle
]
)
let textView = UITextView( frame: CGRect(
x: 20,
y: 25,
width: 260,
height: 400
) )
textView.attributedText = myMutableString
self.view.addSubview( textView )
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
但是当我将那个可变字符串添加到 UITextView 时,它一直在破坏文字。
我去paragraphStyle.lineBreakMode = NSLineBreakMode.byCharWrapping
的时候break没有出现在同一个地方...所以它确实有效果。但这仍然是片面的。我有单词 «call» 在 «c» 之后中断,这太奇怪了。
我可以在故事板编辑器中重现它:
这是预期的行为。根据 Apple 的文档,
byWordWrapping
Wrapping occurs at word boundaries, unless the word itself doesn’t fit on a single line. See Characters and Grapheme Clusters in String Programming Guide for a discussion of issues related to determining word boundaries.
byCharWrapping
Wrapping occurs before the first character that doesn’t fit.
更多信息请参考Apple's Documentation
Aaaaaannnnddd 解决方案是尝试在 sublime text 中编辑我的代码,并意识到电话和电话之间存在不可破坏的 space。
这似乎是一个非常愚蠢的基本功能。为什么 Xcode 不能告诉我...