How can I attach a label to a scrollview in Basic4Android? - basic4android

How can I attach a label to a scrollview at design time (not in the designer)
So I can create a label but the content of my 100% widthx 100% height
label, the long text goes off the screen. Is there a simple way to make the
label scroll without getting too complex? Much appreciated.

Not sure that I exactly understand your question. You should put the label on a ScrollView in order to make it scrollable.
A tutorial about ScrollView is available here.
You can use StringUtils.MeasureMultilineTextHeight to calculate the required height.

Related

Swift: UIScrollView doesn't scroll after the user edits the height of a UITextView

I have two UITextView inside a UIScrollView and the TextView can resize as the user types more text into them. I need the page to be scrollable to account for this so I put them in a ScrollView, however the height of the ContentView doesn't change with the TextViews. Here's what I tried so far:
adding a bottom constraint from the last helper text to the bottom of
the content view with priority 1000 and constant 210. This doesn't
work because the section will be scrollable before the TextViews get
taller and on tablets or larger devices it will make my first
TextView taller.
adding a bottom constraint with a constant of 210 or lower will give me a layout error.
I also thought about calculating the height of the content view and maybe adjusting the constraint based on that but this doesn't work either.
Here is a link to the file in question: https://www.dropbox.com/s/g7q1lbj0pxx14jh/Main.storyboard?dl=0
Any suggestions?
It's also worth noting that the keyboard will cover the second TextView when the first one gets too big so I will eventually need to edit that constraint based on the height of the first TextView (to give it more padding at the bottom so that the user can bring the second TextView in view.
Here is the fixed variant https://www.dropbox.com/s/gujry7ngziaipm7/Main.storyboard?dl=0
I found just 1 error:
You forgot to specify bottom offset from last view in View Container which is UILabel - "Being clear...", so your view container doesn't know when to resize as soon as you do not specified all offsets to it.

UIScrollView Controller not scrolling fully

I am pretty sure this has something to do with the dreaded AutoLayout. (been trying since 2days to get hang of it)
So I mastered it somewhat, but now I have problem where my UIScrollView is not scrolling fully down, pictures are much better at explaining these things
this is the scroll view
this is the content view
so the problem is the scrolling is happening but then again it springs back up. So I am not able to click on the signup button
EDIt 1
Edit:
I have created a little example on github for you to look at, here. The project illustrates the answer below and uses the techniques I describe and nothing else.
Original Answer:
couple of things I would advise here.
First, I know you've been trying for a while but remove all the current constraints (painful I know but). Do this for clarity as ....
The view should be the size of the scene, it looks like you want the scrollview to be the full screen so that too needs to be the size of the scene.
e.g. if you are designing at 6Plus by default the scene size is 414x736 so the view and the scrollview it contains should also be 414x736.
Only the content view needs to be the size of the real content you wish to show. Let's say for arguments sake that the content is 414x1000.
Now the constraints for the scrollview are simple. It needs zero spacing to all it's edges.
You can add the content view to the scrollview in a couple of ways. The way I try to do this varies from project to project and depends mostly on how complex the scene is. If it's a really busy scene I keep the content view outside of the scrollview in interface builder so that I can work on it easily and visualize the whole of the view. Then I add the content view to the scrollview in code.
If its a simpler view You can add it inside the scrollview in interface builder. Ultimately whichever way you do it, you can lose visibility of the content view in interface builder because the contentview is larger than the scrollview and the content gets obscured. So play about and find a good way for you.
Define the content view and all it's subviews. The content view needs to be taller than the scrollview otherwise it wont scroll. All of the content view's subviews need to have defined heights from top to bottom and widths from left to right. In your case the scrollview is scrolling vertically not horizontally so all the widths need to add up to the width of the scroll view BUT the heights need to add up to the full height of the content view.
Note: if you do this proportially your life will be easier later. If you do all this with fixed heights the storyboard will break on different device sizes.
Now the "tricky bit" and it's a bit counter intuitive. You need to pin the content view to the scrollview, remember the height of the content view is taller than the scrollview. In all other circumstances in Interface Builder pinning a view to a superview (0 padding) will adjust the height (or width) accordingly. For the relationship between a scrollview and it's content view this doesn't happen.
First pin the contentview
Notice the -400? Remember the content view is taller than the scrollview and we will change this immediately.
Select the bottom constraint (-400) that we have just created:
Select the drop down arrow next to the constant value:
Select Standard Value and type in 0 for the constant.
You should now have a storyboard with no broken constraints and if you build and run you should get a scrollview as desired.
Your bottomspace to superview on your content view is set to -74.0, I don't know if there is a reason you had to do that, but try setting it to -8.0. I think your scroll view is scrolling up to the 0.0 mark automatically

iOS: how to adjust positions of UI elements one by one properly by IB when some of them may change size?

For example, on a UIView, from left to right there are three buttons:,button1,button2,button3.
When button 1 become wider, such as its width become twice as its original width, is there any interface builder way that can make button2&3 move right automatically?
sorry for I didn't make my question clear.
I mean such kind of size change: I push button1, then I change it's frame in my code, not caused by the change of text in butotn1. I want button2&3 to move right automatically, keeping the width of the gap between button 1 and 2 unchanged.
Thanks everyone.
IB can be used only for initional positioning of views.
True, you can also define autoresizing masks of the views but that's about it.
Any additional laying out should be done in code.
I could be wrong, but I don't know of any way you can do this in IB. It's pretty straight forward in code though, just link the buttons to some IBOutlets and check the sizes of the images of the buttons (myUIImage.size), then adjust the frames of the buttons (do it in viewWillAppear).
Seen your edit - if you're adjusting its size using code, adjust its position too.
If your buttons are in a row at the bottom of the screen, consider using a UIToolBar. Its UIBarButtonItem objects automatically adjust to fit each other's width changes. For more generic cases, you'll need to recalculate positions and sizes as in Franklyn Weber's answer.
Yes - by using autoresizing masks. If you allow the margins to be flexible (no red lines connecting the frame to the superview's frame) and allow flexible width and height, the buttons will size and move proportionally.

How to create a horizontal transparent scroll bar?

I am trying to create something like this (look at the time), you can basically slide it horizontally.
Can anyone give me any suggestions on how to do this in iOS?
You'd use UIScrollView which you can constrain to just horizontal movement. The Scrolling demo may help to get you started.
It is pretty easy:
create a scrollview with frame of (xOrigin,yOrigin,SCREEN WIDTH,Height).
set the content size to (CONTENT WIDTH, Height).
setShowsHorizontolScrollIndicator to no to hide the scroll indicator.
Note: Width of the contentSize property should be greater than the frame width to make it horizontally scrollable.

How to make a UITextView scroll horizontally as the user types?

This seems like it should be simple but I can't work out how to do it.
I've created a UITextView in interface builder. It doesn't sit in a table cell or anything fancy like that.
What I'd like to do is have the UITextView scroll itself to the left when the user has typed their way all the way to the right margin.
At the moment it just does a word wrap, I understand the word wrap makes sense in most situations but I need it to scroll instead. What I'm after is the same behavior it exhibits vertically.
I've tried adjusting the content size of the UITextView in viewDidLoad and also in viewDidAppear and that doesn't make a difference.
I've also played with the inset settings in IB but that doesn't affect the scrollable size, just WHERE it's displayed.
Does anyone have any ideas?
If you only need a single line of text that scrolls, you would probably be better served by a UITextField. UITextViews are meant for multi-line text input, which is why word wrap is the default. You can't, as far as I know, override that behavior.
Ok, it doesn't look like it can be done exactly how I wanted but I've come up with a hack to get me there.
Let's say I want a scrollable width of 600 and a visible width of 250.
The first step is to make the UITextView a wide as the area you want to be scrollable. So what you would have put into contentSize, in this case 600.
Then the right inset is set to the difference between the actual width and the width you wanted. In this case 350.
This way cursor is restrained to the width you need BUT there is text visible to the right of your desired width, after all, the UITextView IS 600 pixels wide.
Now here's where the really hackish bit comes in, don't read on if you're sensitive or have a weak stomach.
Get an image of the user interface to the right where UITextView should end. Insert it into the NIB as an UIImage view and put it back in it's place, making sure that it's on top of the UITextView.
When the view is displayed, the cutout sits on top of the UITextView and hides the text overrun.
I'm not proud, but it works.