我试图让我插入的文本转到另一行,如果它不适合我的 xcode 7。每当我输入比通常适合一行的文本更多的文本而不是像我一样进入第 2 行或第 3 行时指定它只是在标签内拉伸(stretch)自己。有什么我想念的吗?
我在 Collection View 中执行此操作,因此在单元格中执行此操作。以下代码是我如何在运行时将我的文本放入我的 View Controller 中的:
let appleProducts = ["IPADIPADIPADIPADIPADIPADIPADIPADIPADIPAD", "HIIII", "Custom"]
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return self.appleProducts.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CollectionViewCell
cell.titleLabel?.text = self.appleProducts[indexPath.row]
return cell
}
最佳答案
对于多行 UILabel
你应该使用:
label.lineBreakMode = .ByWordWrapping
label.numberOfLines = 0
或者在 Storyboard 中设置 UILabel
Line Breaks
和 Lines
参数
关于ios - 带有文本 Xcode 的标签拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32812518/