2

I'm having some trouble changing the height of a simple textview. It doesn't need to size automatically to the content or anything, I just need to change the height when an iad banner loads and when it's hidden.

all I can find on it, is autoresizing UITextFields.

Hopefully someone can help me out with this simple issue.

The textView was just created in storyboard, but here's the code I currently have related to it:

    @IBOutlet var textViewOutlet: UITextView!
    var textView: String = ""

//after view loads

    textViewOutlet.text = textView

here's what I tried adding in the viewDidLoad:

    textViewOutlet = UITextView(frame: CGRect(x: 0.0, y: 0.0, width: 200.0, height: 40.0))

Which unfortunately doesn't change the size of the textView at all.

The current height of the textView in the storyboard and the app is: 283

*In another viewController I'm also editing the text in the textView using:

detail.textView = "New text here"

which works fine, don't think that has anything to do with the size of the textview but that's everything I have regarding this particular textView

MLyck
  • 4,959
  • 13
  • 43
  • 74

2 Answers2

1

I ended up having to make the textview through code to make it work.

If anyone else is having trouble with resizing a storyboard textView here's what I added to my code to make it manually.

    var textView: UITextView = UITextView(frame: CGRect(x: 5.0, y: 238.0, width: 315.00, height: 283.00))

    textView.text = textViewText
    textView.editable = false
    textView.backgroundColor = UIColor.clearColor()
    textView.font = UIFont(name: "Helvetica", size: 15)
    self.view.addSubview(textView)

Hopefully that helped someone.

*Works with Swift in xcode 6 GM

MLyck
  • 4,959
  • 13
  • 43
  • 74
  • 1
    -1 This does not answer the question but rather differs the question to a quick-fix. – User Sep 29 '14 at 16:16
0

Try this:

myTextView = UITextView(frame: CGRect(x: 0.0, y: 0.0, width: 200.0, height: 40.0))

Hope this helps.. :)

Rashad
  • 11,057
  • 4
  • 45
  • 73
  • Thanks for the quick reply. It's a UITextView not a UITextField I'm having trouble with though. non-the less I tried it and changed Field to view, sadly that didn't do it. But atleast it didn't return an error. Had to use the IBOutlet though. Any idea how to do it with the View? – MLyck Sep 09 '14 at 03:27
  • @user100002> Changing to UITextView should work, add this UITextView(frame: CGRect(x: 0.0, y: 0.0, width: 300.0, height: 150.0)). try this and see if height changes or not. You can set height according to your requirments, – Rashad Sep 09 '14 at 04:12
  • Once again thanks for the quick reply! This is what I tried before. And it didn't change it. Let me find the code I have related to it. (the textView is just set up in interface builder) I'll edit my original post with the added code-snippets. – MLyck Sep 09 '14 at 04:20
  • @user100002 > Are you using auto layout? If yes turn it off and then try. – Rashad Sep 09 '14 at 04:28
  • #Rashad-The Birthday Boy I tried turning it off, besides on of my cellLabels randomly breaking it didn't affect the textView in any way with the code snippet. – MLyck Sep 09 '14 at 06:03
  • Just added information, I updated to xcode 6 GM. Still having serious problems with my UITextView :( – MLyck Sep 10 '14 at 01:08
  • The question is asking how to _change_ the height, not _initially set_ the height. – User Sep 29 '14 at 03:20
  • 1
    @macdonjo > Before downvoting check that user100002 has edited the question after my answer. So don't judge so quickly. And please don't just downvote, if you know any better solution edit the answer. Take care. – Rashad Sep 29 '14 at 05:56
  • Thanks for bringing that to my attention. However, you should delete your answer if its no longer a valid answer to the question given. – User Sep 29 '14 at 18:56