I am creating a Point-of-Sale (POS) receipt and need to have item names with a certain width and need to have a price on the right (like float-right
in CSS
).
I am using https://github.com/FuerteInternational/FTCoreText to create the content. Any ideas how to achieve this without having to create two views and place them on top of each other?
Just to clarify, I need to have this:
Coffee £1.45
milk, skinny
Danish Pastry £1.75
Coca Cola £1.10
Full English Bfst £12.50
So pretty much I need a string to be floating on the left and other string floating on the right ...
In the Word file that you want to insert the text and align to left and right, and then, click Home, in the Paragraph group, click the Paragraph Settings icon, see screenshot: 2. In the Paragraph dialog box, select Left from the Alignment drop down, and then, click Tabs button, see screenshot: 3.
You can’t align content to the left and right margins on the same line using Microsoft Word’s alignment options, but you can still do it using a special tab. We may be compensated by vendors who appear on this page through methods such as affiliate links or sponsored partnerships.
After entering the text in right hand, please put the cursor at the left location where you want to insert text, enter the first line text normally, press the Down arrow in the keyboard to enter a new line (or, you can put the cursor at the next beginning line then type directly). Now, you will get the result as you need, see screenshot:
(1.) Enter a tab number into the Tab stop position text box that means the position where you would like the right hand text to end; (2.) Check Right option in the Alignment section; (3.) Then, click Set button; (4.) At last, click OK button to close this dialog box.
The only thing I can think of is inserting in each string f.e. 30 spaces after the first string and assigning wordWrap = truncate middle. Not so sure that this is exactly what you're looking for.
I agree with Brian Shamblen it'l be pretty easy to do with 2 labels.
It looks like what you want isn't really a second column, which Core Text cannot do out of the box, but rather a tabular layout (like good ol' <table>
). Fortunately tabular layout can be acheived in Core Text by using tab stops. The only 2 things you need are:
CHARACTER TABULATION
(U+0009
) character,That can be done this way:
NSString *string = @"Coffee\t£1.45\n milk, skinny\nDanish Pastry\t£1.75\nCoca Cola\t£1.10\nFull English Bfst\t£12.50";
CGFloat width = 200;
NSArray *tabs = @[CFBridgingRelease(CTTextTabCreate(kCTTextAlignmentRight, width, NULL))];
CTParagraphStyleSetting setting = {kCTParagraphStyleSpecifierTabStops, sizeof(tabs), &tabs};
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(&setting, 1);
NSDictionary *attributes = @{CFBridgingRelease(kCTParagraphStyleAttributeName): CFBridgingRelease(paragraphStyle)};
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:string attributes:attributes];
There are two caveats:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With