Klionar
Klionar

Reputation: 28

Scrollable UIView if there is long text, otherwise nonscollable

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.

Upvotes: 0

Views: 72

Answers (2)

karzler007
karzler007

Reputation: 111

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.

Upvotes: 2

dorian
dorian

Reputation: 847

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.

Upvotes: 2

Related Questions