0

I am not even sure how to formulate this - there is UIView with UIImage, UILabel and UITextField Field. Now if text inside UITextField is long, I would like whole UIView to be scrollable (not only UITextField, that would be easy).

I have tried to make scrollable view with image, text and label inside, but if I make text field unscrollable, the large portion of text is simply not displayed.

Jagat Dave
  • 1,643
  • 3
  • 23
  • 30
Klionar
  • 28
  • 4
  • 1
    You may want to stretch the size of the Text Field, and set the `Content Size` of the scrollable view accordingly – zc246 Feb 17 '16 at 11:13
  • Yeah, just found some more info, and it seems like a good idea. But can I adjust Content Size depending on how long text is? Like if it would be image, I could use something like frame.size.height – Klionar Feb 17 '16 at 11:17
  • You may want to use UITextView suggested by Anbu, and change the size of it shown [here](http://stackoverflow.com/q/50467/2710486). Then you can get the `frame.size.height` and use it for scrollable content size. – zc246 Feb 17 '16 at 11:23

2 Answers2

2

I had a similar problem, and used UITableView as a solution. Each cell in the table view can be a custom view. (Text/Label/Image as you'd like it to be)

For your text, you may simply have a WebView embedded into one of the table view cells, while making sure that the delegate for the webView's scrollView is set to the TableView.

Based on problems that people usually face with webView in TableView you may have to detect the content size of your text and dynamically resize the cell height, and call reload.

There's yet another possible approach you could take (if you want to avoid UIWebView) - NSAttributedString. You may set the cell's `textLabel?.attributedText' to an attributed string, which would preserve the desired effect you want.

And before you do that, make sure you set the 'cell.textLabel?.numberOfLines' to 0.

karzler007
  • 111
  • 9
2

If you set the numberoflines property of your UITextField to 0 like _txtField.numberoflines = 0, then it should automatically adjust the content size. Make sure you have the right constraints in place between your UIScrollView that contains your other views like UIImageView, UILabel and UITextFiled.

Jagat Dave
  • 1,643
  • 3
  • 23
  • 30
dorian
  • 847
  • 5
  • 11