My structure consist of
- uiview
- scrollview
- contentview
- uitextview
- uibutton
What I'm trying to achieve is to adjust the height of scrollview according to textview height or content. Textview gets its text on run accordingly. So when i have a long text in my textview, scrollview adjusts itself so all textview's content is visible by scrolling.
Related
I used the vertical stack view to hold two UIView.Second UIView has a textArea.But I could not find a way to change the UIview height when the height of TextView change
In my view I have a scrollview.
In my scrollview I have a UILabel.
I use constraints to set my scrollview in my superview and also for my UILabel.
If I set a long text inside my UILabel the scrollview's content extends to the width of my UILabel.
Instead of that, I would like the content view set to maximum width of my screen and the UILabel goes to multilines.
How can I do this ?
Try setting your label's number of line to 0 and preferredMaxLayoutWidth the width you want, then call setNeedsLayout with your main view.
I have a fixed size UITextView and if I add more word's, it will scroll to it's content. I'm adding an UIImage as a subview in UITextView. If there are more comment's I cannot scroll UITextView to see the image. Can we set the content height of uitextview to solve this issue?
UITextView is not designed to receive a subview like that, and it won't scroll it correctly. You need to add both as subviews in a UIScrollView, which should auto-behave like so:
Swiping should first scroll the view where the touchDown event began (i.e., your UITextView)
When that view has no more to scroll, the event should bubble up to the UIScrollView itself, bringing up your UIImage.
If you don't like this behavior then you can synchronize scrolling as you prefer by calculating the height of your text inside your UITextView bounds, using:
CGSize size = [myText sizeWithFont:myFont forWidth:myFontWidth.0 lineBreakMode:UILineBreakModeWordWrap];
I have a simple case:
I have the following views hierarchy:
View
ScrollView
View
Label
My label is positioned at the bottom of it's super view, and it's height is changed dynamically, depending ot the size of the text that it is rendering.
My aim is to adjust the label size depending on the text, so that no text is truncated, and with the growth of the lines of the label, to grow the scrollview's content size, so that the label always is positioned at the bottom.
How can I do that with autolayouts, preferably from IB only?
If you want the UILabel to stick at the bottom of its parent UIView using autolayout, then that view won't expand its height when the UILabel height increase, what really happens is that the UILabel will move up to occupy more area.
I f you wish your UIView to expand, then don't use autolayout in that UIView, and position your UILabel at a constant origin, then change the view's height & the scrollview height as per the UILabel text.
you can get the UILabel size using the below line of code:
CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:yourLabel.lineBreakMode];
I have a scrollView with a UIView as subview, which in turn has many subviews, one of which is a textView with variable height. This is the hierarchy of views:
-UIScrollView
- UIView
-UITextView with variable height
-UImages
As can dynamically vary the height of the UIView and finally the scrollView based on the length of the content?
When the user edits your UITextView field, get its bounds height and recalculate the overall size of you scrollable view, then set UIScrollView's contentSize property.
You can detect the end of editing on a UITextView object by means of its UITextViewDelegate textViewDidEndEditing: method.