How can I hide a label if another label is taking up X number of lines? - swift

Say I have two labels, one on top of the other. Label 1 is set to have a maximum number of lines of 2 (numberOfLines=2). So sometimes, depending on the text, Label 1 can take up TWO lines. The thing though is that a maximum of 2 lines should be shown between both labels, where Label 1's second line takes precedence over Label 2. (Also, Label 2 is always 1 line.)
So either of these 2 scenarios are possible:
Label 1 text
Label 2 text
OR
Label 1 text (line 1)
Label 1 text (line 2)
The only way I thought to attack this was to simply hide Label 2 if Label 1 is taking up 2 lines. But the problem is, how can I determine how many lines Label 1 is taking up?
I've found a few other answers about this (1, 2), but none seem to work for me. Is there perhaps a better way to go about this?

In my opinion, you should just use one label, and construct the text seperately by the code and pass the final text into the label. In order to have a new line, you can use "\n". If you want to have a different fonts/color etc, you can always use AttributedString. This will be much cleaner, easier to change, and more flexible to maintain in the future.

Did you working with Constraint? or Did you have knowledge about NSLayoutConstraints?
you can easily do that with managing proper constraint and it doesn't matter how many line will text have you can show both label with text.
make sure label.numberofline = 0. // It will take line as text.

Related

Display multiple lines in SKLabelNode

I checked there is no properties for multiline in SKLabelNode.
Is it possible to display multiple lines in SKLabelNode?
If no, Please give idea to display text in multilines.
I use this bit of code to get multi lines of code with SKLabelNode.
Multilines in a label-github
There is a way now to do multi-line SKLabelNodes.
Set the property numberOfLines to 0. From Apple's documentation:
The default value is 1 (a single line). A value of 0 in interpreted as an unlimited number of lines. If the height of the text reaches the number of lines, the text will be truncated using the line break mode.

iText split PdfPCell when cell is kept together

I am using a table to create a semblance of what is depicted below. The content I'm generating isn't known before hand. The blue sections of the columns are cells that are kept together in the table and I am using ColumnText to display the table. For clarification I have outlined a sample cell layout in the top right of the image. The problem I'm running into is that when I use setSplitLate(false) with setSplitRows(true) alongside with using keepRowsTogether(int[] rows) the splitting doesn't work correctly. Most of the top right section should be able to fit into the bottom left but as shown in the image it is all moved to the top of the next column.
Is there a way to cause the cell to split as well as keep together with it's header? When I remove the keepRowsTogether(int[] rows) call the cell splitting works as expected.
Also, in my situation I only want it to split if there are two lines at the end of the column and two at the beginning of the next. In other words the cell would only split if it contained 4 lines of text. How would I go about doing this?
I modified the top right column as depicted below, blue representing the rows that are kept together.
As depicted, I have a cell for the header as before but I've split up the paragraph into many different cells. The first and last contain cells with two lines of text and the rest contain one line of text. This way I'm guaranteed that the header will stick with at least the first two lines of the bulleted paragraph. If the last two lines, or the last cell, end up not fitting in the column then because the cell contains two lines, I'm guaranteed that at least two lines will be carried over to the next column, if not more, depending on how many of the middle lines carry over as well.

Making one of the column dividers thicker than the others in a browse

I have a browse with 5 columns. I want the dividing line between columns 3 and 4 to be a little thicker.
Is there a way to do this?
Short answer is no, you can't change the line between columns.
But you could add an empty dummy column with blank values between column 3 and 4, that you could get to look it like a thicker separator.
Regards,

iOS: Aligning two UILabels (left/right) and connecting with dots?

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:#"."]
}

Creating a fixed formatted cell in UITableview

I want to have a tableview create rows that look like this:
value1 item1 container1
value10 item10 container10
value100 item100 container100
value2 item2 container2
What I am trying to show is that the first word (value) will have a set length of 12 and then the second word (item) will have a set length of 10 and then the last word (container) is just tagged on at the end.
I am pulling these from a SQLite database and don't want to use multiple lines, but read in a strictly formatted structure like this.
You can layout a custom UITableViewCell in Interface Builder, where you drag two UILabel views onto the Content View and set their size appropriately (Notice that the letters may vary in width, so even though you know it's 10 chars in length, you don't know the maximum width, please keep that in mind)
Then you just fill the open space at the right of a cell with another UILabel, layout it to cover the open space and set it to autoresize it's width and set the right margin to be fixed.
There are quite a few tutorials available on how to use the custom cell in your tableView, I can recommend you this screencast. It explains how you can initialize the custom cell and how you can access the custom labels.
It sounds like you want something like an old-fashion text display in which then nth character in row zero always lines up the nth character in every row.
Even using carefully positioned labels in a custom tableviewcell, you will have to strictly control the specific font and its size if you want all the characters to line up in fixed width column. You will need a fixed width font to begin with and you will have to set the size precisely.
You might want to consider whether this is necessary. iPhone users are used to propionate width text displays. Very precise columns of text might make it difficult to discern rows. I would test first with just a simple table before spending the time tweaking the columns.