Aligning half line to the left and the second to the right in CoreText

Viewed 1303

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 ...

4 Answers

I recently came across this problem and found no answers.. so I created a class for anyone that needs it! Let's say you want to create a list of strings like the example in the question:

- (void)createReceipt {

    NSString *coffee = [LRString LRStringWithLeft:@"Coffee" right:@"£1.45" maxlength:29 maxleft:16 maxright:11];

}

This "coffee" string would look like this:

Coffee                  £1.45

"maxlength" is the maximum length of your string
"maxleft" is the maximum length of your left string (coffee)
"maxright" is the maximum length of your right string (price)

If the name exceeds the "maxleft" length, then the last 3 letters of the name (coffee) will be replaced with "..."

Check it out on GitHub here: https://github.com/iosdec/LRString

Related