I have set auto layout constraints to my text view and now when I rotate the device app sometimes automatically scrolls text view to the end of content. For example in case when I have many words in the textview and the content size is bigger then text view, then I see not a top word but see instead bottom words. And never see the First word of text.
As you can see the text is cut off on the visible first line. Because it scrolled. But I just want to see top of text view not a bottom.
Related
I currently have an app which displays questions and answers as text in textview objects. These textviews are wrapped in stackviews along with navigation buttons.
If I set the textview to non-scrollable (by unchecking the scrollable button) the text displays, but long text runs off the screen and of course the user can't scroll down to read it. If I check the scrollable button, the text isn't displayed at all - just blank space.
Any idea how I can either: set the text to be scrollable and display or set the text to autoshrink (as it doesnt run over by much).
That much to say about textViews -> Replace the textViews with labels with 0 of lines -> This guarantees that the label will be autoshrinking vertically, just set width and the stackView into scrollView and you are at it :)
I have a weird behavior when I use scrollView.
As you can see in the picture bellow the button called "Back" has a bottom space constraint with value 0. But we can see is not even near to the bottom of the scroll view.
I already set the scrollview to have equals width and height of the superView and top,bottom,trailing and leading space with 0 value.
How can I fix this? I want the Back button still inside of the scrollview and put it at the bottom of the view.
Update
I have the code here https://github.com/rchampa/NDParallaxIntroView and the xib is called PageB.xib
Ricardo: you've added two constraint regarding manage y position of Validate Code button where your top constraint stop to move Validate Code button towards the bottom. So please remove top constraint of Validate Code only add bottom constraint.
you need to manage all constraint like your scrollview content view height will be equal to height. Please increase some top constraint from top.
So, if I understand correctly, the problem you are running into is that your back button is unable to be positioned based on the bottom of the scroll view.
A scroll has two sets of constraints in a storyboard, one that defines the size of the scroll view, and the other that defines the content size. The top, left, bottom, right to superview constraints on the scroll view will define the size.
The part that is causing your problem is that the content size is defined by the subviews inside the scroll view. So the button cannot be placed relative to the bottom of the scroll view since the scroll view doesn't know how large its content size is. All of the subviews of a scroll view must be placed in relation to each other.
So, create constraints for your logo, text fields, and all the buttons in relation to each other. Then create constraints from the outer most subviews to the scroll view.
In your example, you would constraints from the logo to the text field, 1st text field to 2nd text field, then 2nd text flied to the label, label to the "Send email..." button, and finally "Send email..." to the "Validate Code". For the "Back" button, it would need a left align with the text fields and then a center align with the "Validate Code" button. Create a top constraint from the logo to the scroll view. Then have leading and trailing constraints from one of the text fields to the scroll view. Finally, create a bottom constraint from either the "Back" or "Validate Code" buttons to the scroll view. You will also need some alignment constraints (logo center to the text field is an example of one). After that is all setup, your view will be fully defined for the content size of the scroll view.
If I understand you, my new question is: how can I make the subviews
make the height of scroll fit 100% screen device height? Is there a
way to define weights like Android? I don't know how achieve this
since the canvas is 600*600 which is different to every device.
Response would be too long for a comment:
So you wouldn't use a scroll view for that. A scroll view is specifically for containing content that will not fit on the screen (so the user can scroll to reach the new content).
The simplest solution is to add a regular view that has TopLeftBottomRight 0 distance constraints (so it is the max height and width of the screen) and setup the view like you have here to position the bottom in the bottom left all the time.
There is also a weight system, I can explain that if you want, but it wouldn't be required thus far.
I feel like your next response will be something like "what if I want it to scroll when its too small for the current screen?". The only way I know of doing that in encapsulating all your interface into a single UIView, and changing its sized in the viewDidLoad/viewDidAppear based on the size of the scroll view. Something like this:
func viewDidLoad() {
super.viewDidLoad()
containerViewHeightConstraint.constant = scrollView.frame.size.height
containerViewWidthConstraint.constant = scrollView.frame.size.width
}
I have a UILabel that covers most of the view. When I place text in the label, the text is center in the middle of the label. I have tried everything by playing around with the options in the attributes inspector, however the text wont start in the top area of the label, instead it appears in the middle of the label.
Is there any way to places the text in the top part of the label??
(If someones is wondering, yes I want the UILabel to cover most of the view because some texts are longer then others, and some are shorter, and I would prefer the text to be placed on the top part and not the middle of the UIlLabel.)
UILabel has an intrinsicContentSize matching the text contents. If you don't constrain the height, then it will automatically adjust. So you don't need to make it cover the entire view.
Instead, tag it onto the top with a fixed distance. Specify the bottom distance with greater-than-or-equal. This way the label can grow until it reaches the lower limit and then the text will begin to be truncated.
I have a form on one of my pages in my app.
The form is enclosed with a scrollview , the content of the form (originally made 320x568 in size) is now sitting in a frame of 320x408
now, if i put the same view in this frame without the scrollview, all of it contents shrinks (the spaces between the views shrink, and the entire thing fits and works in the given frame).
Now, i wanted to make this form responsive to the keyboard, meaning when the keyboard showed on the screen, i wanted to scroll some of the views above the keyboard. So i thought i'd enclose them inside a scrollview
I added the scrollview to the viewcontroller's screen, and put all the views inside with the exact same constraints.
However, the content of the scrollview does not seem to adjust to the fact that the content size is now 320x408 instead of 320x568, and so some of the screen is out of view, and needing to scroll up to see it.
How do i make it so i don't need to scroll up, if the keyboard is not present ?
I am working with storyboards and have put text inside a table cell within a ViewController. The text shows up correctly in portrait view without need for set constraints. However, on landscape view without constraints the text does not fill the entire width. Thus, I apply constraints to fill the canvas with text but the top part of the text does not appear.
I have this hierarchy:
View Controller
Table View
Table View Section
Table View Cell
Content View
Label
Constraints
(Constraints are set for vertical top, and both horizontal sides)
I have autolayout checked, working with attributed text, word wrap, with about 30 lines and indent head at 20. Without an indent the clipping or cutting off does not occur, but it makes my text start about midway on the screen as opposed to just below the navigation bar.
Any help with this would be much appreciated.
EDIT: Attached Link https://www.flickr.com/photos/115284261#N02/sets/72157640082717193/