I'm trying to learn Auto Layout and playing around with various view combinations. I have various views containing other views, but the one I'm having trouble with is one that contains a label and a text field. They are set up like this:
There are several constraints set up on these, such as center Y alignment between the label, text field, and parent view, 0 leading edge for the label, and a hard coded value (12, but irrelevant) for the trailing edge of the text field. I had initially had it as a 0 trailing edge, aligning it with the parent container. However, the right edge of the text field seems to be cutting off and I have no idea why... I Started increasing the distance, thinking that may be there's a margin issue, but nothing seems to help!
Would love any input.
Related
Alright, I do not know how to fix this and only ran into this problem after trying to put in some longer text on a UI Text component. I have tried both pasting a value into its Text attribute through the Unity editor, and setting its value programmatically like this:
t.GetComponent<Text> ().text = "This is where meat, fish, and [...] (long text)"
Because Horizontal wrap is on, the text wraps when it reaches the edge of the available space.
However, the text displays backwards. Meaning, the start of the paragraph is at the bottom, and bottom at the top. Taking off wrap fixes this, but then the font size has to be really small (or it won't all be visible), and it can't form a normal paragraph because it has to... you know... wrap.
Is this a bug in Unity?
This is what happens - as you can see, it is displayed backwards:
The negative Line Spacing value is what is causing the issue here:
When the value of this field is less than 0, the lines will actually be arranged backwards, leading to the behaviour you're currently encountering. Just change the value to a positive number to have the text display correctly.
I have a scenario in which my reports fields doesn't look like centered Vertically,
Below is the screen Short of the output.
As it can bee seen from output that data with a bigger font is clearly seen centered vertically, but the data pointed with lines is left-top justified, i want that to be left-centered.
For vertical alignment I did this .
and code behind formula is:
if {NewReport;1.TireLevel} = 1
then
crCenteredHorizontally
else
crLeftAligned
The Editor Screen.
Sadly, Crystal Reports doesn't support vertical alignment in the same way it supports horizontal.
It's possible to use labels on the vertical ruler and enforce Snap to Grid, but that might not work within a table. Or you can add line breaks, blank rows, or plain white objects to push things into position. But there's no easy way to enforce a vertical center.
In your particular case, I would actually make two seperate fields: One for large text and one for small text. Layer them on top of each other and reuse your current formula to alternate their suppression. This way you can move the smaller text vertically down without undoing the vertical alignment on the large text field.
The scene has a container view inside of a superview, and I've constrained it with respect to the boundaries and 2 text boxes. Instead of "Numeric Value Please", I only see Nu... appearing on there. The console does not give me any constraint related warnings, and I don't understand why the blue view is able to fit in, but the controller is not.
Here are Alert Controller's constraints: http://i.stack.imgur.com/2xhZh.png. It's just constrained to the center.
Another picture of main view's constraints: http://i.stack.imgur.com/2qARq.png
The constraint to the right is too large (125), pushing the right edge of the container to the left.
You should just have: constraint from top (superview), constraint to left (the text field), height (optional), and slightly higher compression resistance. To prevent the text from going off to the right you can also have a >= constraint to the right (superview).
To break the text into two lines, set number of lines to 2 and choose "Word Wrap" + make sure you have a right side constraint and you are not constraining the height (too much).
Another remark: do you really need a "container" view? Why not just a plain UIView? Or does the label have its own controller? That seems like a somewhat convoluted design I think.
I am working on a Swift project with Storyboards where I want text to wrap in a label. In the old Objective-C version where I did not use a Storyboard I used the following settings and things worked perfectly.
Here are the settings for Swift
I have been reading about the potential auto layout issues with preferred width settings. I currently have them set to auto layout and the label itself is set to a width of 560. I've added a constraint to keep the label 20 pixels from the trailing superview and while I thought this would work I still cannot get the text to wrap. The dimension settings are below.
Can someone explain how to get the text to wrap?
First, the good news: You have set the label to 2 lines and Word Wrap. So it can wrap. Excellent.
Now you must make sure the label is tall enough. Either give it no height constraint, or give it a big enough height constraint that it can accommodate two lines.
Finally, you must limit its width. This is what causes the text to wrap. If you don't limit the label's width, it will just keep growing rightward, potentially continuing off the screen. The limit on the label's width stops this rightward growth and causes the text to wrap (and the label to grow downward instead).
You can limit width in several ways. You can have an actual width constraints. Or you can have a leading constraint and a trailing constraint, to something relatively immovable, such as the superview. And there is a third way: on the Size inspector (which you do also show, at the bottom right of your question), set the Preferred Width (it is shown at the top of the Size inspector): this is the width at which, all other things being equal, the label will stop growing to the right and wrap and grow down instead.
Declare your UILabel programmatically and give
yourUILabel.contentMode = .scaleToFill
yourUILabel.numberOfLines = 0
yourUILabel.leadingMargin(pixel: 10)
yourUILabel.trailingMargin(pixel: 10)
This worked for me.
Your text will wrap if you have provided lines number more than 1. However you may not be able to see it wrap if the label height is not enough to show the content. I suggest you to remove the height constraint or increase its value.
In case this helps anybody: I had followed the advice given here to fix my label not wrapping to two lines but nothing worked. What worked for me was I first deleted some of the relevant constraints in storyboard (I'm using auto layout) and saw that the label wrapped properly. I slowly added back the constraints I needed and everything still seems to work fine. So deleting and remaking your constraints may help.
What fixed this problem was changing the label type to "Placeholder" under Intrinsic Size in IB. When I changed this the text wrapped and the warnings went away.
As I see you interface builder. There are two problems. First one is with your constraints, and another one is with the property.
You gave it a fixed height which is wrong while line wrap. You need to make the auto-resizing label, i.e. remove height and add the bottom constraint or simple remove height depend on your situation. Your text is moving to the next line, but due to fixed constraint, you can't see it.
You enable the option to clip subviews which is wrong as it cuts your view and you are unable to view wrap word.
Add a new case:
DO NOT add constraints to your label with a TEXTVIEW, or the label will expand to right without limitation.
In my case i set my parent stackview alignment from center to fill and set UILabel to
label.textAlignment = NSTextAlignment.right
The above image was taken from an Android app. I am looking to do the same thing on iOS. I know how to do it using a background image for the dots, but it doesn't look like the Android developer used an image for the dots. Anyone know how this can be done?
I've found the way to do it with content hugging/compression resistance.
Here is the interface builder solution:
Left label has a phrase and lots of dots with line breaking = truncate tail. Content hugging/compression resistance do the rest of job.
I think you can do this without any code. Just use two labels with their baselines aligned, and with a horizontal spacing constraint of 0. The left label would have its text left aligned with say 10 dots added to the end of the string, and the line break mode set to "clips". The right label would also be left aligned, so its text would always be right up against the dots.
After Edit: I couldn't get this to work in IB. It may be possible in code using constraints, but I haven't tried that. It seems like you should be able to do it with 3 labels, with the two outside ones pinned to the edges of the view, and a flexible label in the middle whose text would be dots.
You can use NSAttributedString to format in that way.
Use two colors in two ranges, even bold font for 2nd part.
And calculate the total width (length of your text) and fill dots (.) in between those.
An idea to fill dots:
lets say you have 30 characters space.
str1 contains 10, str2 contains 6, then use 30-(10+6) then in a loop
for(30-(10+6) times) {
[mainString appendString:#"."]
}