多行可编辑文本:可编辑的 UILabel?

Multi-line editable piece of text: editable UILabel?

我正在尝试创建一大块可编辑文本,但似乎有 1 个选项:使用小型 UITextField。

我知道 UILabel 可以很大很宽,但我不知道如何制作可编辑的 UILabel。

我尝试了 UILabel 属性和 .layer 方法,但似乎没有任何效果。有人对我应该做什么有建议吗?

总而言之,我正在寻找一段多行可编辑的文本。

UITextView 获胜!!

UITextViews 允许对文本进行多行操作,如果您使用 UITextViewDelegate,它可以提供在单击 textView 时允许特定操作的方法,等等...!

使用 UITextView,您可以提供特定数量的行(如果您只需要 3 行,您可以指定)并在需要时提供超链接。

这是我的一个例子(稍作改动),以供您参考...

let textBox:UITextView = UITextView(frame: CGRect(x: firstBox.frame.width*0, y: firstBox.frame.height*0.375, width: firstBox.frame.width*1, height: firstBox.frame.height*0.5))
        textBox.backgroundColor = UIColor.clearColor()

        let websiteName = "http://whosebug.com/posts/38035564"
        textBox.text = "SO is an awesome coding site! Please visit\n\(websiteName)"

        //No need to set number of lines, it will auto set to as many as needed!
        textBox.editable = false
        textBox.selectable = true

        //Register the hyperlink
        textBox.dataDetectorTypes = UIDataDetectorTypes.All
        textBox.textColor = UIColor.grayColor()

        //Change only the hyperlink part
        let textRange = NSMakeRange(textBox.text.characters.count-websiteName.characters.count, websiteName.characters.count)
        let style = NSMutableParagraphStyle()
        style.alignment = NSTextAlignment.Center

        let attributedText = NSMutableAttributedString(string: textBox.text, attributes: [NSFontAttributeName:UIFont(
            name: (textBox.font?.fontName)!,
            size:13/15*fontSize)!,
            NSParagraphStyleAttributeName: style])
        attributedText.addAttribute(NSUnderlineStyleAttributeName , value:NSUnderlineStyle.StyleSingle.rawValue, range: textRange)
        textBox.attributedText = attributedText
        firstBox.addSubview(textBox)