【发布时间】:2015-09-25 14:11:36
【问题描述】:
这是我的 UILabel 代码...
var maximumLabelSize: CGSize = (chosenSpecies.identifyingCharacteristics![index] as NSString).sizeWithAttributes([NSFontAttributeName: UIFont.systemFontOfSize(16)])
var identifyingCharacteristicsInformation = UILabel(frame: (CGRectMake(leftMargin, spacingValue, maximumLabelSize.width, maximumLabelSize.height)))
identifyingCharacteristicsInformation.font = UIFont(name: "HelveticaNeue-Light", size: informationTextSize)
identifyingCharacteristicsInformation.textAlignment = NSTextAlignment.Left
identifyingCharacteristicsInformation.text = chosenSpecies.identifyingCharacteristics![index]
identifyingCharacteristicsInformation.text = identifyingCharacteristicsInformation.text!.capitalizedString
identifyingCharacteristicsInformation.textColor=UIColor(red:0.0, green:0.0, blue:0.0, alpha:1)
identifyingCharacteristicsInformation.numberOfLines = 0
identifyingCharacteristicsInformation.lineBreakMode = NSLineBreakMode.ByWordWrapping
identifyingCharacteristicsInformation.preferredMaxLayoutWidth = pictureContainer.frame.width
ScrollView.addSubview(identifyingCharacteristicsInformation)
spacingValue += identifyingCharacteristicsInformation.frame.height
scrollView.contentSize.height += identifyingCharacteristicsInformation.frame.height
这就是发生的事情。这些“特征”中的每一个都是使用上面的代码在 for 循环中打印的。正如您所看到的,那些在屏幕上长时间运行的特征。
我一直在网上搜索为什么这可能会发生几个小时并且一直没有结果。有没有人知道为什么会发生这种情况?我在使用自动换行时遇到了困难,因为我的理解并不完整。只需实现这两行代码,我就可以将它应用到代码中的其他地方。
label.numberOfLines = 0
label.lineBreakMode = NSLineBreakMode.ByWordWrapping
这是我对 Eric Qian 建议的尝试。我目前正在申请它。
var maxSize: CGSize = CGSize(width: 320, height: 100)
var maximumLabelSize: CGRect = (chosenSpecies.identifyingCharacteristics![index] as NSString).boundingRectWithSize(maxSize, options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(16)], context: nil)
【问题讨论】:
标签: ios swift text uilabel word-wrap