ios - 带有文本 Xcode 的标签拉伸(stretch)

标签 ios xcode swift xcode7

我试图让我插入的文本转到另一行,如果它不适合我的 xcode 7。每当我输入比通常适合一行的文本更多的文本而不是像我一样进入第 2 行或第 3 行时指定它只是在标签内拉伸(stretch)自己。有什么我想念的吗?

ViewController:

XCode

我在 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 BreaksLines 参数

关于ios - 带有文本 Xcode 的标签拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32812518/

相关文章:

ios - 如何使用 Swift 获取应用程序版本和内部版本号?

swift - 字典中频率最高的元素

ios - 如何在 iOS 中使用 UIActivityViewController 创建和保存特定相册

ios - UITableView "Content"字段未出现在 XIB 文件中(Xcode 5 和 6)

ios - 不同设备上的 BLE 外设名称不同

ios - 检测应用程序在加载期间崩溃/上次运行时崩溃?

swiftUI 如何在键盘上设置搜索按钮

ios - 管理两个目标 iOS 的单个屏幕

objective-c - 带有 ffmpeg dylibs 的 Cocoa 应用程序在 Mac OSX 10.5(但不是 10.6 或 10.7)上崩溃

xcode - 如何从 Xcode 的搜索中排除注释行?