2016-06-26 23 views
0

編集可能なテキストの大きなプロットを作成しようとしていますが、小さなUITextFieldを使用する1つのオプションがあるようです。複数行の編集可能なテキスト:編集可能なUILabel?

私はUILabelsが大きくて広いことができますが、編集可能なUILabelを作成する方法はわかりません。

私はUILabelプロパティと.layerメソッドを試しましたが、実際には何も動作していないようです。誰が私が何をすべきかについての勧告を持っていますか?

要約すると、私は複数行の編集可能なテキストを探しています。

答えて

2

勝利のための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://stackoverflow.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) 
+0

...私はyaのための一例を示すように(少し変更)している例です! 2つの金の星! 1つは正解、2番目はあなたの熱意です。乾杯! –

+0

ありがとうございます!質問/コメントをここに投稿してください。私は助けに行くでしょう!コーディングの冒険に幸運を祈る! – impression7vx

関連する問題