I'm working in an app to draw text on UIImage. I display the image on screen and a UILabel on it describing the text. User can edit the text. I set lineBreakMode to UILabel to be WordWrap. Now when I get the text to be drawn on the UIImage to export it as an Image. The text drawn as one line although it was displayed as multi line on the screen because of the wordwrapping.
Is there a way to replace the wrapped works with linebreak "\n". For example "Lorem Ipsum" when I display it in small size label, "Ipsum" will be drawn in new line. So I need I call getText, I get it as "Lorem\nIpsum"
It sounds like the problem is the number of lines you have. I had a similar problem before where the words didn't cut off. Add this line of code to your project:
label.numberOfLines = 3
You can set the number of lines to whatever you need. It should now put each word on a new line. Cheers!
Related
I'm printing an adhesive label (6x5cm) with a printer model 3nStar RPT006.
In the adhesive I am printing a title, QR code and the QR code in text
something like this
My Title
▄
qr code
Using this class as reference, I'm doing something like this:
initialize(),
setJustification(Printer.JUSTIFY_CENTER),
'My Title',
feed(),
qr(qrText),
feed(),
qrText,
feed(2),
cut(Printer.CUT_FULL, 1),
My problem is: I don't know how to control the vertical size, or how to set the height of the paper. Between each label I have a gap of 3mm.
So my question is, how should I handle the vertical spacing/height?
Currently I very close to get a perfect label, but seems like the printed label is some millimeters shorter and each time I print a label, it miss a little bit more, so there is a time where I start to cut the adhesive part and not the gap
I'm not sure if it's possible in your environment, but there are three options.
Prepare blank image data with the required number of vertical dots and print it(graphics(EscposImage $image, $size)) instead of the line feed code.
Use setLineSpacing($height) to change the height of one line only for the required part and start a new line. Then return to the original size.
Make your own customization by adding the function to feed the paper in dot units to the library for printing.
ESC J
How to achieve TextAlignment.justified on one line of a label.
I have one UILabel of fixed width (200)
Number of lines of this Label is always 1
I want the text of this One Line to be justified on both edges
So far What I have seen the TextAlignment.justified is only applied on paragraph and also on paragraph it is not applied on last line or single line.
For a UILabel of certain width, with certain font and font size, i want to calculate amount of characters that would make 7 lines worth of text inside it + ... (three dots showing continuation). Is there a fancier way to achieve this? Currently what i'm trying is counting up to X amount of characters or 7 new line characters, which ever comes first and i cut on the text right there.
More Detail:
Trying to make an expandable row Cell which contains the UILabel, i'm achieving this with auto layout... So to control the cell expansion, i change the text to be full text or a substring of that, with a button below which toggles between the string vs substring. All of that is working. The problem i'm getting is my method of finding the substring isnt very neat. Its not consistent on how it handles text of different combination of characters or newlines. I get variations of how it looks and sometimes it just ends with three dots on a new line rather than finishing on the 7th line.
Even using auto layout you can still use the lines property of UILabel to limit the number of lines displayed by the label.
So set it 7 and you'll get 7 or less rows. Just assign the complete text.
For example, I have the following two string: "How Munched is That Birdie in the Window?" and "S22 - E7". I want to present in the label the following: "How Munched is That Birdie in ... S22 - E7" If the string is too large according to the label's size and doesn't fit it". How you can see, the three dots are placed always in the first string, the second string is always shown full.
How can I achieve this?
Here is how to do it.
yourlabel.adjustsFontSizeToFitWidth = false
yourlabel.lineBreakMode = .byTruncatingMiddle
You can set the UILabel's ParagraphStyle LineBreakMode to byTruncatingMiddle, which will probably work in most cases with carefully planned label size. From the docs:
The line is displayed so that the beginning and end fit in the container and the missing text in the middle is indicated by an ellipsis glyph. This mode is used for single-line layout
If you want to guarantee none of the "S22 - E7" string is truncated, you would have more control using two labels and setting layout constraints such that the width of the protected label is preserved so that it can display the full string whenever possible, but that is probably overkill in most cases.
You may also find this answer helpful if decide to go a different route by manually manipulating the displayed string based on detecting how many characters will be visible given the width and font.
I have a whole paragraph and I want to fit it in a label and be justified.Also, I want every line to have a specific range of words. I know that there is "Autoshrink" in Xcode, but it does not seem to work because I am trying it in a multiline text.
Here is an example of what I am trying to do http://imgur.com/Kxbs64Q. You can see how the text is fit into the label and is justified. However, not every line has the same number of characters. Is there a way to compress the text inside the label in swift?.
Use a minimumFontSize for your label. It will allow you to fit all of your text in the label. Also, set your label's numberOfLines to 0 if you want label to automatically create multiple lines. Use this link for help.