Receipt alignment is not working properly in swift

2019-02-20 15:56发布

问题:

I am currently printing receipt from my data when i print my receipt alignment data is not working properly

i think that i should apply start index and end index to string

because my product name length is different So i apply this code to check length of string

here is screenshot of Receipt

you can see in receipt alignment is wrong

Here is my code to give alignment and receipt

   if       ProductName.characters.count > 13 {let subStr = ProductName[ProductName.startIndex.advancedBy(0)... ProductName.characters.count(13)]
            strtext.appendString(String (format: "%@ %@                       %@\n", sQuantity,subStr,s))
            textData.appendString(strtext as String)
        }

my requirement is first quantity,name and price should be come My receipt alignment is not proper

anyone can help me solve this issue?

回答1:

your code is fine additionally , there is the option in Epson Printer in

enum EposOcAlign {
 EPOS_OC_ALIGN_LEFT = 0,
 EPOS_OC_ALIGN_CENTER,
 EPOS_OC_ALIGN_RIGHT
};

the method is invoked as - (int) addTextAlign:(int)align; use align type as center and try once