在我的代码(Swift 2.0 iOS 9)中,我创建了一个UIScrollView并添加了一个UILabel到 ScrollView 以显示大量文本。文本通过加载viewDidLoad()并从包中的文件加载。
我用过numberOfLines = 0,label.lineBreakMode = .ByWordWrapping但只显示了 8 行文本。在代码下方,您将看到代码结果的图像。我给了颜色UILabel并UIScrollView显示了它们的界限。
override func viewDidLoad() {
super.viewDidLoad()
self.configureView()
let sv = UIScrollView(frame: self.view.bounds)
sv.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
self.view.addSubview(sv)
sv.backgroundColor = UIColor.greenColor()
var y: CGFloat = 10
let file = detailItem as! String
if let sectionsFile = NSBundle.mainBundle().pathForResource(file, ofType: "txt") {
if let sectionText = try? String(contentsOfFile: sectionsFile, usedEncoding: nil) {
let label = UILabel()
label.numberOfLines …Run Code Online (Sandbox Code Playgroud)